import { Button, Col, Form, Input, List, Row, Space, Tag } from "antd"; import { ItemGrid } from "../Components/ItemGrid"; import { NLView } from "../types"; import { SearchItemWidget } from "../Components/SearchItemWidget"; import { Spin } from "../Components/Spin"; import { useActions, useAppState } from "../overmind"; import { useLocation } from "react-router-dom"; import React, { useEffect } from "react"; // TODO: Maybe move to utils or something function useQuery() { const { search } = useLocation(); return React.useMemo(() => new URLSearchParams(search), [search]); } export const useCreativeSearchQuery = () => { const query = useQuery(); const tags = query.get("tags") ?? ""; const index: number = Number(query.get("index") ?? 0); const aesthetics = query.get("aesthetics") ?? ""; return { tags, aesthetics, index }; }; export const SearchCreative: NLView = () => { const state = useAppState(); const actions = useActions(); const { tags, aesthetics } = useCreativeSearchQuery(); useEffect(() => { actions.routing.setBreadcrumbs([{ text: "Creative Search" }]); actions.lists.creativeSearch({ tags, aesthetics }); }, []); const search = (tags: string, aesthetics: string) => { if (tags === "") { return; } if (aesthetics === "") { actions.routing.historyPush({ location: `/search-creative?tags=${tags}`, }); } else { actions.routing.historyPush({ location: `/search-creative?tags=${tags}&aesthetics=${aesthetics}`, }); } actions.lists.creativeSearch({ tags, aesthetics }); }; const maybeLoadMore = () => { actions.lists.creativeSearch({ tags, aesthetics }); }; const [form] = Form.useForm(); useEffect(() => { form.setFieldsValue({ q: state.lists.creativeSearch.lastQueried.tags }); }, [state.lists.creativeSearch.lastQueried]); const lastQueried = state.lists.creativeSearch.lastQueried; const items = state.lists.creativeSearch.results.items; return (