-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ffxiv-export-url-endings #490
base: master
Are you sure you want to change the base?
Changes from 3 commits
bccd397
3069ba4
a7684b9
eb98ae7
31f9626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
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' | ||
|
@@ -20,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<string, string> = { | ||
hqOnly: 'High Quality Only', | ||
|
@@ -46,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) { | ||
|
@@ -101,13 +141,21 @@ const Index = () => { | |
const results = useActionData< | ||
ItemServerComparisonList | { exception: string } | {} | ||
>() | ||
const loaderData = useLoaderData<typeof defaultFormValues>() | ||
|
||
const [modal, setModal] = useState<'exportServers' | 'items' | null>(null) | ||
const [state, setState] = useState<{ | ||
items: string[] | ||
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<HTMLButtonElement>) => { | ||
if (transition.state === 'submitting') { | ||
e.preventDefault() | ||
|
@@ -137,7 +185,8 @@ const Index = () => { | |
onClick={onSubmit} | ||
loading={transition.state === 'submitting'} | ||
disabled={transition.state === 'submitting'} | ||
error={error}> | ||
error={error} | ||
action={getActionUrl('/queries/world-comparison', state)}> | ||
<div className="pt-4"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai this does change the url of the page but loading something like Can you look through other past pull requests to see how we fixed this before and recommend a fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cohenaj194, it seems that there are no past pull requests that directly address the issue of populating form fields based on URL parameters. However, I can recommend a solution based on the current context. The issue likely stems from the form fields not being initialized with the data returned by the Here's an example of how you can implement this: const Index = () => {
const transition = useNavigation();
const results = useActionData<
ItemServerComparisonList | { exception: string } | {}
>();
const loaderData = useLoaderData<typeof defaultFormValues>();
const [state, setState] = useState({
items: loaderData.itemIds.split(','),
exportServers: loaderData.exportServers.split(','),
hqOnly: loaderData.hqOnly === 'true',
});
// Rest of the component code...
}; In this example, the Let me know if you need further assistance with this! Analysis chainScripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search through past pull requests for keywords related to URL parameters and form population.
gh pr list --search "URL parameters form population" --json number,title,body --limit 10
Length of output: 93 Script: #!/bin/bash
# Perform a broader search for past pull requests using more general keywords related to query parameters and form data.
gh pr list --search "query parameters form data" --json number,title,body --limit 10
Length of output: 727 Learnings added
Learnings used
|
||
<div className="sm:px-4 flex flex-col gap-4"> | ||
<div className="flex flex-col max-w-full relative"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI recommendation, this might be right, but it does not solve the whole problem.