diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f273923..c419689 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,46 +1,52 @@ import { IconSearch } from "@tabler/icons-solidjs"; import clsx from "clsx"; import Fuse from "fuse.js"; -import { For, createSignal } from "solid-js"; -import { SearchCardContact } from "./components/search-card/SearchCardContact"; +import { For, createEffect, createResource, createSignal } from "solid-js"; import { SearchCardEvent } from "./components/search-card/SearchCardEvent"; import { SearchCardLocation } from "./components/search-card/SearchCardLocation"; -import { SearchCardNote } from "./components/search-card/SearchCardNote"; -import { SearchCardReceipt } from "./components/search-card/SearchCardReceipt"; -import { SearchCardWebsite } from "./components/search-card/SearchCardWebsite"; -import { sampleData } from "./network/sampleData"; -import type { DataItem } from "./network/types"; +import { UserImage, getUserImages } from "./network"; import { getCardSize } from "./utils/getCardSize"; -const getCardComponent = (item: DataItem) => { +const getCardComponent = (item: UserImage) => { switch (item.type) { - case "Location": + case "location": return ; - case "Event": + case "event": return ; - case "Contact": - return ; - case "Website": - return ; - case "Note": - return ; - case "Receipt": - return ; + // case "Contact": + // return ; + // case "Website": + // return ; + // case "Note": + // return ; + // case "Receipt": + // return ; default: return null; } }; function App() { - const [searchResults, setSearchResults] = createSignal([]); + const [searchResults, setSearchResults] = createSignal([]); const [searchQuery, setSearchQuery] = createSignal(""); - const [selectedItem, setSelectedItem] = createSignal(null); + const [selectedItem, setSelectedItem] = createSignal( + null, + ); - const fuze = new Fuse(sampleData, { - keys: [{ name: "title", weight: 2 }, "rawData"], + const [data] = createResource(getUserImages); + + let fuze = new Fuse(data() ?? [], { + keys: [{ name: "title", weight: 2 }, "data"], threshold: 0.4, }); + createEffect(() => { + fuze = new Fuse(data() ?? [], { + keys: [{ name: "data.Name", weight: 2 }], + threshold: 0.4, + }); + }); + const onInputChange = (event: InputEvent) => { const query = (event.target as HTMLInputElement).value; setSearchQuery(query); @@ -98,7 +104,7 @@ function App() { )} > - {item.title} + {item.data.Name} {getCardComponent(item)} diff --git a/frontend/src/components/search-card/SearchCardEvent.tsx b/frontend/src/components/search-card/SearchCardEvent.tsx index 8febd33..0a98bd7 100644 --- a/frontend/src/components/search-card/SearchCardEvent.tsx +++ b/frontend/src/components/search-card/SearchCardEvent.tsx @@ -1,10 +1,10 @@ import { Separator } from "@kobalte/core/separator"; import { IconCalendar } from "@tabler/icons-solidjs"; -import type { Event } from "../../network/types"; +import type { UserImage } from "../../network"; type Props = { - item: Event; + item: Extract; }; export const SearchCardEvent = ({ item }: Props) => { @@ -13,12 +13,12 @@ export const SearchCardEvent = ({ item }: Props) => { return (
-

{data.title}

+

{data.Name}

- Organized by {data.organizer.name} on{" "} - {new Date(data.dateTime.start).toLocaleDateString("en-US", { + Organized by TODO on{" "} + {new Date(data.StartDateTime).toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric", @@ -26,7 +26,7 @@ export const SearchCardEvent = ({ item }: Props) => {

- {data.description} + {data.Description}

); diff --git a/frontend/src/components/search-card/SearchCardLocation.tsx b/frontend/src/components/search-card/SearchCardLocation.tsx index 56f47ac..bae2e0d 100644 --- a/frontend/src/components/search-card/SearchCardLocation.tsx +++ b/frontend/src/components/search-card/SearchCardLocation.tsx @@ -1,10 +1,10 @@ import { Separator } from "@kobalte/core/separator"; import { IconMapPin } from "@tabler/icons-solidjs"; -import type { Location } from "../../network/types"; +import type { UserImage } from "../../network"; type Props = { - item: Location; + item: Extract; }; export const SearchCardLocation = ({ item }: Props) => { @@ -13,13 +13,13 @@ export const SearchCardLocation = ({ item }: Props) => { return (
-

{data.name}

+

{data.Name}

-

{data.address}

+

{data.Address}

- {data.description} + {data.Description}

); diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index e278ff1..72457e4 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -82,9 +82,9 @@ const eventDataType = object({ const dataTypeValidator = variant("type", [locationDataType, eventDataType]); const getUserImagesResponseValidator = array(dataTypeValidator); -export const getUserImages = async (): Promise< - InferOutput -> => { +export type UserImage = InferOutput; + +export const getUserImages = async (): Promise => { const request = getBaseRequest({ path: "image" }); const res = await fetch(request).then((res) => res.json());