fix: make search usable again
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { IconStar, IconStarFilled } from "@components/icons.tsx";
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { Signal, useSignal } from "@preact/signals";
|
||||
import { useState } from "preact/hooks";
|
||||
|
||||
export const SmallRating = (
|
||||
@@ -24,27 +24,31 @@ export const SmallRating = (
|
||||
};
|
||||
|
||||
export const Rating = (
|
||||
props: { max?: number; rating: number },
|
||||
{ max, rating = useSignal(0) }: {
|
||||
max?: number;
|
||||
defaultRating: number;
|
||||
rating: Signal<number | undefined>;
|
||||
},
|
||||
) => {
|
||||
const [rating, setRating] = useState(props.rating);
|
||||
const [hover, setHover] = useState(0);
|
||||
const max = useSignal(props.max || 5);
|
||||
|
||||
const ratingValue = rating.value || 0;
|
||||
|
||||
return (
|
||||
<div
|
||||
class="flex items-center gap-2 px-5 rounded-2xl bg-gray-200 z-10"
|
||||
class="flex items-center gap-2 px-5 rounded-2xl bg-gray-200 z-10 h-full"
|
||||
style={{ color: "var(--foreground)", background: "var(--background)" }}
|
||||
>
|
||||
{Array.from({ length: max.value }).map((_, i) => {
|
||||
{Array.from({ length: max || 5 }).map((_, i) => {
|
||||
return (
|
||||
<span
|
||||
class={`cursor-pointer opacity-${
|
||||
(i + 1) <= rating ? 100 : (i + 1) <= hover ? 20 : 100
|
||||
(i + 1) <= ratingValue ? 100 : (i + 1) <= hover ? 20 : 100
|
||||
}`}
|
||||
onMouseOver={() => setHover(i + 1)}
|
||||
onClick={() => setRating(i + 1)}
|
||||
onClick={() => (rating.value = i + 1)}
|
||||
>
|
||||
{(i + 1) <= rating || (i + 1) <= hover
|
||||
{(i + 1) <= ratingValue || (i + 1) <= hover
|
||||
? <IconStarFilled class="w-4 h-4" />
|
||||
: <IconStar class="w-4 h-4" />}
|
||||
</span>
|
||||
|
||||
@@ -12,17 +12,25 @@ export type Props = {
|
||||
searchResults?: GenericResource[];
|
||||
};
|
||||
|
||||
function getQFromUrl(u: string | URL): string | null {
|
||||
try {
|
||||
const _u = typeof u === "string" ? new URL(u) : u;
|
||||
return _u?.searchParams.get("q");
|
||||
} catch (_e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export const MainLayout = (
|
||||
{ children, url, context, searchResults }: Props,
|
||||
) => {
|
||||
const _url = typeof url === "string" ? new URL(url) : url;
|
||||
const hasSearch = _url?.search?.includes("q=");
|
||||
const q = getQFromUrl(url);
|
||||
|
||||
if (hasSearch) {
|
||||
if (typeof q === "string") {
|
||||
return (
|
||||
<Search
|
||||
q={_url.searchParams.get("q") || ""}
|
||||
{...context}
|
||||
q={q}
|
||||
results={searchResults}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user