From 66e3741948bddcfef6aed8b0f6e7e2d6e3a62cfb Mon Sep 17 00:00:00 2001 From: Peter Hozak Date: Sat, 10 Feb 2024 13:35:33 +0000 Subject: [PATCH 1/2] redirect ?state urls (#382 part 1) --- app/routes/_index.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index d479daad..23205daa 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -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' @@ -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> = {data: [], timestamp: ''} export const loader = async ({request}: Parameters[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} From c4899c9d60d65ff86eb8ec5173e7d17c419bb471 Mon Sep 17 00:00:00 2001 From: Peter Hozak Date: Sat, 10 Feb 2024 15:36:14 +0000 Subject: [PATCH 2/2] make eslint happy --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index b7cbb4ec..5ad89477 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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: