-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to move articles to tutorials and setup a redirect
- Loading branch information
Showing
16 changed files
with
192 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { AppLoadContext } from "@remix-run/cloudflare"; | ||
|
||
import { z } from "zod"; | ||
|
||
export class Redirects { | ||
constructor(protected loadContext: AppLoadContext) {} | ||
|
||
async list() { | ||
let { keys } = await this.loadContext.kv.redirects.list(); | ||
return RedirectSchema.array().parse(keys.map((key) => key.metadata)); | ||
} | ||
|
||
async add(name: string, from: string, to: string) { | ||
await this.loadContext.kv.redirects.put( | ||
name, | ||
JSON.stringify({ from, to }), | ||
{ metadata: { from, to } }, | ||
); | ||
} | ||
} | ||
|
||
const RedirectSchema = z.object({ from: z.string(), to: z.string() }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const INTENT = { | ||
import: "IMPORT_ARTICLES" as const, | ||
reset: "RESET_ARTICLES" as const, | ||
moveToTutorial: "MOVE_TO_TUTORIAL" as const, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const INTENTS = { | ||
export const INTENT = { | ||
clear: "CLEAR_CACHE" as const, | ||
deleteSelected: "DELETE_SELECTED" as const, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { loader } from "./route"; | ||
|
||
import { useLoaderData } from "@remix-run/react"; | ||
import { GridList, GridListItem } from "react-aria-components"; | ||
|
||
export function RedirectsList() { | ||
let { list } = useLoaderData<typeof loader>(); | ||
|
||
return ( | ||
<GridList | ||
aria-label="Redirects" | ||
selectionMode="multiple" | ||
className="flex flex-col gap-0.5 rounded-md border border-neutral-300 p-1 data-[focus-visible]:outline-2 data-[focus-visible]:outline-blue-600" | ||
> | ||
{list.map((redirect) => { | ||
return ( | ||
<GridListItem | ||
key={redirect.from + redirect.to} | ||
textValue={`From: ${redirect.from} To: ${redirect.to}`} | ||
className="data-[selected]:bg-grey-100 flex items-center gap-2.5 rounded-md p-1 pl-2 data-[selected]:text-blue-600" | ||
> | ||
{/* <StyledCheckbox value={key} /> */} | ||
From: {redirect.from} - To: {redirect.to} | ||
</GridListItem> | ||
); | ||
})} | ||
</GridList> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { | ||
ActionFunctionArgs, | ||
LoaderFunctionArgs, | ||
} from "@remix-run/cloudflare"; | ||
|
||
import { redirect, json } from "@remix-run/cloudflare"; | ||
import { Form } from "@remix-run/react"; | ||
import { useId } from "react"; | ||
|
||
import { Logger } from "~/modules/logger.server"; | ||
import { Redirects } from "~/modules/redirects.server"; | ||
import { SessionStorage } from "~/modules/session.server"; | ||
|
||
import { RedirectsList } from "./list"; | ||
|
||
export async function loader({ request, context }: LoaderFunctionArgs) { | ||
void new Logger(context).http(request); | ||
|
||
let user = await SessionStorage.requireUser(context, request, "/auth/login"); | ||
if (user.role !== "admin") throw redirect("/"); | ||
|
||
let redirects = new Redirects(context); | ||
let list = await redirects.list(); | ||
|
||
return json({ list }); | ||
} | ||
|
||
export async function action({ request, context }: ActionFunctionArgs) { | ||
void new Logger(context).http(request); | ||
|
||
let user = await SessionStorage.requireUser(context, request, "/auth/login"); | ||
if (user.role !== "admin") throw redirect("/"); | ||
|
||
return redirect("/cms/cache"); | ||
} | ||
|
||
export default function Component() { | ||
let id = useId(); | ||
|
||
return ( | ||
<div className="flex flex-col gap-8 pb-10"> | ||
<header className="flex justify-between gap-4 px-5"> | ||
<h2 className="text-3xl font-bold">Redirects</h2> | ||
|
||
{/* <div className="flex items-center gap-4"> | ||
</div> */} | ||
</header> | ||
|
||
<Form method="post" id={id}> | ||
<RedirectsList /> | ||
</Form> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const INTENT = { | ||
clear: "CLEAR_CACHE" as const, | ||
deleteSelected: "DELETE_SELECTED" as const, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters