From bccd3975ac1ee82cf31ef613300efd321c4b482b Mon Sep 17 00:00:00 2001 From: Alex Cohen Date: Sun, 1 Sep 2024 12:08:14 -0400 Subject: [PATCH 1/3] ffxiv-export-url-endings --- app/routes/queries.world-comparison.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/app/routes/queries.world-comparison.tsx b/app/routes/queries.world-comparison.tsx index 85e1e17d..02d8e8c2 100644 --- a/app/routes/queries.world-comparison.tsx +++ b/app/routes/queries.world-comparison.tsx @@ -1,3 +1,4 @@ +// add url endings to this file https://github.com/ff14-advanced-market-search/saddlebag-with-pockets/issues/489 import { useActionData, useNavigation } from '@remix-run/react' import { ContentContainer, PageWrapper, Title } from '~/components/Common' import SmallFormContainer from '~/components/form/SmallFormContainer' From 3069ba46455811bc3af6ec0c6cdbe41a71036c65 Mon Sep 17 00:00:00 2001 From: Alex Cohen Date: Sun, 1 Sep 2024 12:32:13 -0400 Subject: [PATCH 2/3] Update queries.world-comparison.tsx --- app/routes/queries.world-comparison.tsx | 47 +++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/app/routes/queries.world-comparison.tsx b/app/routes/queries.world-comparison.tsx index 02d8e8c2..f66fe247 100644 --- a/app/routes/queries.world-comparison.tsx +++ b/app/routes/queries.world-comparison.tsx @@ -1,5 +1,4 @@ -// add url endings to this file https://github.com/ff14-advanced-market-search/saddlebag-with-pockets/issues/489 -import { useActionData, useNavigation } from '@remix-run/react' +import { useActionData, useLoaderData, useNavigation } from '@remix-run/react' import { ContentContainer, PageWrapper, Title } from '~/components/Common' import SmallFormContainer from '~/components/form/SmallFormContainer' import type { ActionFunction } from '@remix-run/cloudflare' @@ -21,6 +20,10 @@ import { } from '@heroicons/react/outline' import { WorldList } from '~/utils/locations/Worlds' import TitleTooltip from '~/components/Common/TitleTooltip' +import { + getActionUrl, + handleSearchParamChange +} from '~/utils/urlSeachParamsHelpers' const pathHash: Record = { hqOnly: 'High Quality Only', @@ -47,6 +50,42 @@ export const links: LinksFunction = () => [ } ] +// Define default form values +const defaultFormValues = { + itemIds: '', + exportServers: '', + hqOnly: 'false' +} + +// Define input schema for validation +const inputSchema = z.object({ + itemIds: z.string().min(1), + exportServers: z.string().min(1), + hqOnly: z.optional(z.string()) +}) + +// Loader function to handle URL parameters +export const loader: LoaderFunction = async ({ request }) => { + const params = new URL(request.url).searchParams + + const values = { + itemIds: params.get('itemIds') || defaultFormValues.itemIds, + exportServers: + params.get('exportServers') || defaultFormValues.exportServers, + hqOnly: params.get('hqOnly') || defaultFormValues.hqOnly + } + + const validParams = inputSchema.safeParse(values) + if (!validParams.success) { + return json({ + exception: `Missing: ${validParams.error.issues + .map(({ path }) => path.join(', ')) + .join(', ')}` + }) + } + return json(validParams.data) +} + const sortByPrice = (desc: boolean) => (first: { price: number }, second: { price: number }) => { if (first.price === second.price) { @@ -102,6 +141,7 @@ const Index = () => { const results = useActionData< ItemServerComparisonList | { exception: string } | {} >() + const loaderData = useLoaderData() const [modal, setModal] = useState<'exportServers' | 'items' | null>(null) const [state, setState] = useState<{ @@ -138,7 +178,8 @@ const Index = () => { onClick={onSubmit} loading={transition.state === 'submitting'} disabled={transition.state === 'submitting'} - error={error}> + error={error} + action={getActionUrl('/queries/world-comparison', state)}>
From a7684b9878d41dcb4c85057778331dca6feec0dd Mon Sep 17 00:00:00 2001 From: cohenaj194 Date: Sun, 1 Sep 2024 13:03:03 -0400 Subject: [PATCH 3/3] adding ai recommendation --- app/routes/queries.world-comparison.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/routes/queries.world-comparison.tsx b/app/routes/queries.world-comparison.tsx index f66fe247..c87b4a3a 100644 --- a/app/routes/queries.world-comparison.tsx +++ b/app/routes/queries.world-comparison.tsx @@ -149,6 +149,13 @@ const Index = () => { exportServers: string[] }>({ items: [], exportServers: [] }) + // // One AI recommendation, but it didnt solve the issue. It keeps saying "Error: Cannot read properties of undefined (reading 'split')" + // const [state, setState] = useState({ + // items: loaderData.itemIds ? loaderData.itemIds.split(',') : [], // Add a check for undefined + // exportServers: loaderData.exportServers ? loaderData.exportServers.split(',') : [], // Add a check for undefined + // hqOnly: loaderData.hqOnly === 'false', + // }) + const onSubmit = (e: React.MouseEvent) => { if (transition.state === 'submitting') { e.preventDefault()