feat: some shit

This commit is contained in:
max_richter 2023-08-08 21:55:10 +02:00
parent c7d0e97ac0
commit fb96e9f71a
5 changed files with 34 additions and 18 deletions

View File

@ -1,14 +1,25 @@
import { isLocalImage } from "@lib/string.ts"; import * as CSS from "https://esm.sh/csstype@3.1.2";
export function Image(
props: { class: string; src: string; width?: number; height?: number },
) {
if (isLocalImage(props.src)) {
}
const Image = (
props: {
class: string;
src: string;
alt?: string;
width?: number | string;
height?: number | string;
style?: CSS.HtmlAttributes;
},
) => {
return ( return (
<div> <img
<img src={props.src} width={props.width} height={props.height} /> alt={props.alt}
</div> style={props.style}
src={props.src}
width={props.width}
height={props.height}
class={props.class}
/>
); );
} };
export default Image;

View File

@ -1,14 +1,17 @@
import { Card } from "@components/Card.tsx"; import { Card } from "@components/Card.tsx";
import { Movie } from "@lib/resource/movies.ts"; import { Movie } from "@lib/resource/movies.ts";
import { Series } from "@lib/resource/series.ts"; import { Series } from "@lib/resource/series.ts";
import { isLocalImage } from "@lib/string.ts";
export function MovieCard({ movie }: { movie: Movie }) { export function MovieCard({ movie }: { movie: Movie }) {
const { meta: { image = "/placeholder.svg" } = {} } = movie; const { meta: { image = "/placeholder.svg" } = {} } = movie;
const imageUrl = image?.startsWith("Media/movies/") const imageUrl = isLocalImage(image)
? `/api/images?image=${image}&width=200&height=200` ? `/api/images?image=${image}&width=200&height=200`
: image; : image;
console.log({ imageUrl, image });
return ( return (
<Card <Card
title={movie.name} title={movie.name}

View File

@ -5,6 +5,7 @@ import {
IconExternalLink, IconExternalLink,
} from "@components/icons.tsx"; } from "@components/icons.tsx";
import { isLocalImage } from "@lib/string.ts"; import { isLocalImage } from "@lib/string.ts";
import Image from "@components/Image.tsx";
export function RecipeHero( export function RecipeHero(
{ data, subline, backlink, editLink }: { { data, subline, backlink, editLink }: {
@ -28,7 +29,7 @@ export function RecipeHero(
> >
{imageUrl && {imageUrl &&
( (
<img <Image
src={imageUrl} src={imageUrl}
alt="Recipe Banner" alt="Recipe Banner"
style={{ objectPosition: "0% 25%" }} style={{ objectPosition: "0% 25%" }}

View File

@ -9,6 +9,7 @@ import { IS_BROWSER } from "$fresh/runtime.ts";
import Checkbox from "@components/Checkbox.tsx"; import Checkbox from "@components/Checkbox.tsx";
import { Rating } from "@components/Rating.tsx"; import { Rating } from "@components/Rating.tsx";
import { useSignal } from "@preact/signals"; import { useSignal } from "@preact/signals";
import Image from "@components/Image.tsx";
export const RedirectSearchHandler = () => { export const RedirectSearchHandler = () => {
useEventListener("keydown", (e: KeyboardEvent) => { useEventListener("keydown", (e: KeyboardEvent) => {
@ -30,7 +31,7 @@ const SearchResultImage = ({ src }: { src: string }) => {
: src; : src;
return ( return (
<img <Image
class="object-cover w-12 h-12 rounded-full" class="object-cover w-12 h-12 rounded-full"
src={imageSrc} src={imageSrc}
alt="preview image" alt="preview image"
@ -76,7 +77,7 @@ export const SearchResultList = (
); );
}; };
const SearchComponent = ( const Search = (
{ q, type }: { q: string; type?: string }, { q, type }: { q: string; type?: string },
) => { ) => {
const [searchQuery, setSearchQuery] = useState(q); const [searchQuery, setSearchQuery] = useState(q);
@ -185,4 +186,4 @@ const SearchComponent = (
); );
}; };
export default SearchComponent; export default Search;

View File

@ -1,5 +1,5 @@
import { Head } from "$fresh/runtime.ts"; import { Head } from "$fresh/runtime.ts";
import Image from "@components/Image.tsx";
export default function Error404() { export default function Error404() {
return ( return (
@ -9,7 +9,7 @@ export default function Error404() {
</Head> </Head>
<div class="px-4 py-8 mx-auto bg-[#86efac]"> <div class="px-4 py-8 mx-auto bg-[#86efac]">
<div class="max-w-screen-md mx-auto flex flex-col items-center justify-center"> <div class="max-w-screen-md mx-auto flex flex-col items-center justify-center">
<img <Image
class="my-6" class="my-6"
src="/logo.svg" src="/logo.svg"
width="128" width="128"