Skip to content
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

redirect ?state urls (#382 part 1) #387

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {LoaderFunction} from '@remix-run/cloudflare'
import {ShouldRevalidateFunction, useOutletContext, useLoaderData} from '@remix-run/react'
import {loadTags} from '~/server-utils/stampy'
import {ShouldRevalidateFunction, useOutletContext, useLoaderData, redirect} from '@remix-run/react'
import {QuestionState, loadTags} from '~/server-utils/stampy'
import Header from '~/components/Header'
import Footer from '~/components/Footer'
import type {Context} from '~/root'
Expand All @@ -10,9 +10,22 @@ import {PageSubheaderText} from '~/components/PageSubHeader'
import {ContentBoxMain, ContentBoxSecond, ContentBoxThird} from '~/components/ContentBox'
import Grid from '~/components/Grid'
import useToC from '~/hooks/useToC'
import {getStateEntries} from '~/hooks/stateModifiers'

const empty: Awaited<ReturnType<typeof loadTags>> = {data: [], timestamp: ''}
export const loader = async ({request}: Parameters<LoaderFunction>[0]) => {
const url = new URL(request.url)
const stateFromUrl = url.searchParams.get('state')
if (stateFromUrl) {
const firstOpenId = getStateEntries(stateFromUrl).filter(
([_, state]) => state === QuestionState.OPEN
)[0]?.[0]
if (firstOpenId) {
url.searchParams.delete('state')
url.pathname = `/${firstOpenId}`
throw redirect(url.toString())
}
}
try {
const tags = await loadTags(request)
return {tags}
Expand Down
Loading