Skip to content

Commit

Permalink
Merge pull request #387 from StampyAI/link-redirect
Browse files Browse the repository at this point in the history
redirect ?state urls (#382 part 1)
  • Loading branch information
Aprillion committed Feb 10, 2024
2 parents 73e2b92 + c4899c9 commit a4f4abb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rules:
react-hooks/rules-of-hooks: error
react-hooks/exhaustive-deps: error
"@typescript-eslint/no-explicit-any": off
"@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_"}]
react/no-unescaped-entities: ["error", {"forbid": [">", "}"]}]
unused-imports/no-unused-imports: "error"
settings:
Expand Down
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

0 comments on commit a4f4abb

Please sign in to comment.