From b359e9d61d9d2c5fe8b39ba138259a2f5644e9d8 Mon Sep 17 00:00:00 2001 From: Dmytro Kondakov Date: Mon, 17 Mar 2025 21:05:49 +0100 Subject: [PATCH] fix: linter and format issues format --- frontend/src/App.tsx | 231 +++++++++++++++++----------------- frontend/src/network/index.ts | 148 +++++++++++----------- 2 files changed, 191 insertions(+), 188 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a3a716b..9d4e043 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -11,138 +11,141 @@ import { getUserImages } from "./network"; type UserImages = Awaited>; function App() { - const [searchResults, setSearchResults] = createSignal< - UserImages[number]["Text"] - >([]); + const [searchResults, setSearchResults] = createSignal< + UserImages[number]["Text"] + >([]); - const [images] = createResource(getUserImages); + const [images] = createResource(getUserImages); - const nav = useNavigate(); + const nav = useNavigate(); - let fuze = new Fuse[number]>([], { - keys: ["Text.ImageText"], - }); + let fuze = new Fuse[number]>([], { + keys: ["Text.ImageText"], + }); - // TODO: there's probably a better way? - createEffect(() => { - const userImages = images(); + // TODO: there's probably a better way? + createEffect(() => { + const userImages = images(); - console.log(userImages); - if (userImages == null) { - return; - } + console.log(userImages); + if (userImages == null) { + return; + } - const imageText = userImages.flatMap((i) => i.Text ?? []); + const imageText = userImages.flatMap((i) => i.Text ?? []); - fuze = new Fuse(imageText, { - keys: ["ImageText"], - threshold: 0.3, - }); - }); + fuze = new Fuse(imageText, { + keys: ["ImageText"], + threshold: 0.3, + }); + }); - const onInputChange = (query: string) => { - // TODO: we can migrate this searching to Rust, so we don't abuse the main thread. - // But, it's not too bad as is. - setSearchResults(fuze.search(query).flatMap((s) => s.item)); - }; + const onInputChange = (query: string) => { + // TODO: we can migrate this searching to Rust, so we don't abuse the main thread. + // But, it's not too bad as is. + setSearchResults(fuze.search(query).flatMap((s) => s.item)); + }; - return ( -
-
- { - if (item?.ImageID == null) { - console.error("ImageID was null"); - return; - } + return ( +
+
+ { + if (item?.ImageID == null) { + console.error("ImageID was null"); + return; + } - nav(`/image/${item.ImageID}`); - }} - optionValue="ID" - optionLabel="ImageText" - placeholder="Search for stuff..." - itemComponent={(props) => ( - - - {props.item.rawValue.ImageText ?? ""} - - - )} - > - - - - - } - > - - - - - - - - e.preventDefault()} - > - - - 😬 No emoji found - - - - -
- {/*
+ nav(`/image/${item.ImageID}`); + }} + optionValue="ID" + optionLabel="ImageText" + placeholder="Search for stuff..." + itemComponent={(props) => ( + + + {props.item.rawValue.ImageText ?? ""} + + + )} + > + + + + + } + > + + + + + + + + e.preventDefault()} + > + + + 😬 No emoji found + + + + +
+ {/*
Emoji selected: {emoji()?.emoji} {emoji()?.name}
*/} - -
-
-
- {/*
+ +
+
+
+ {/*
*/} - {/* {JSON.stringify(images())} */} - - {(image) => ( - - - - )} - -
-
-
-
- footer -
-
- ); + {/* {JSON.stringify(images())} */} + + {(image) => ( + + + + )} + +
+ + +
+ footer +
+
+ ); } export default App; diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index ac35c4b..34ecad5 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -1,102 +1,102 @@ import { - array, - InferOutput, - null as Null, - nullable, - object, - parse, - pipe, - string, - uuid, + type InferOutput, + null as Null, + array, + nullable, + object, + parse, + pipe, + string, + uuid, } from "valibot"; type BaseRequestParams = Partial<{ - path: string; - body: RequestInit["body"]; - method: "GET" | "POST"; + path: string; + body: RequestInit["body"]; + method: "GET" | "POST"; }>; const getBaseRequest = ({ path, body, method }: BaseRequestParams): Request => { - return new Request(`http://localhost:3040/${path}`, { - headers: { userId: "fcc22dbb-7792-4595-be8e-d0439e13990a" }, - body, - method, - }); + return new Request(`http://localhost:3040/${path}`, { + headers: { userId: "fcc22dbb-7792-4595-be8e-d0439e13990a" }, + body, + method, + }); }; const sendImageResponseValidator = object({ - ID: pipe(string(), uuid()), - ImageID: pipe(string(), uuid()), - UserID: pipe(string(), uuid()), + ID: pipe(string(), uuid()), + ImageID: pipe(string(), uuid()), + UserID: pipe(string(), uuid()), }); export const sendImage = async ( - imageName: string, - base64Image: string, + imageName: string, + base64Image: string, ): Promise> => { - const request = getBaseRequest({ - path: `image/${imageName}`, - body: base64Image, - method: "POST", - }); + const request = getBaseRequest({ + path: `image/${imageName}`, + body: base64Image, + method: "POST", + }); - request.headers.set("Content-Type", "application/base64"); + request.headers.set("Content-Type", "application/base64"); - const res = await fetch(request).then((res) => res.json()); + const res = await fetch(request).then((res) => res.json()); - return parse(sendImageResponseValidator, res); + return parse(sendImageResponseValidator, res); }; const getUserImagesResponseValidator = array( - object({ - ID: pipe(string(), uuid()), - Image: object({ - ID: pipe(string(), uuid()), - ImageName: string(), - Image: Null(), - }), - Tags: nullable( - array( - object({ - ID: pipe(string(), uuid()), - TagID: pipe(string(), uuid()), - ImageID: pipe(string(), uuid()), + object({ + ID: pipe(string(), uuid()), + Image: object({ + ID: pipe(string(), uuid()), + ImageName: string(), + Image: Null(), + }), + Tags: nullable( + array( + object({ + ID: pipe(string(), uuid()), + TagID: pipe(string(), uuid()), + ImageID: pipe(string(), uuid()), - Tag: object({ - ID: pipe(string(), uuid()), - Tag: string(), - UserID: pipe(string(), uuid()), - }), - }), - ), - ), - Links: nullable( - array( - object({ - ID: pipe(string(), uuid()), - Links: string(), - ImageID: pipe(string(), uuid()), - }), - ), - ), - Text: nullable( - array( - object({ - ID: pipe(string(), uuid()), - ImageText: string(), - ImageID: pipe(string(), uuid()), - }), - ), - ), - }), + Tag: object({ + ID: pipe(string(), uuid()), + Tag: string(), + UserID: pipe(string(), uuid()), + }), + }), + ), + ), + Links: nullable( + array( + object({ + ID: pipe(string(), uuid()), + Links: string(), + ImageID: pipe(string(), uuid()), + }), + ), + ), + Text: nullable( + array( + object({ + ID: pipe(string(), uuid()), + ImageText: string(), + ImageID: pipe(string(), uuid()), + }), + ), + ), + }), ); export const getUserImages = async (): Promise< - InferOutput + InferOutput > => { - const request = getBaseRequest({ path: "image" }); + const request = getBaseRequest({ path: "image" }); - const res = await fetch(request).then((res) => res.json()); + const res = await fetch(request).then((res) => res.json()); - return parse(getUserImagesResponseValidator, res); + return parse(getUserImagesResponseValidator, res); };