mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
refactor: migrate route definitions to path builders
This commit is contained in:
@@ -72,7 +72,7 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path={`${ROUTES.WRITE()}:public_id?`}
|
path={ROUTES.WRITE}
|
||||||
element={
|
element={
|
||||||
<ProtectedRoute>
|
<ProtectedRoute>
|
||||||
<Editor />
|
<Editor />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { ROUTES } from "../../config/routes";
|
import { PATHS } from "../../config/routes";
|
||||||
|
|
||||||
export function LetterItem({
|
export function LetterItem({
|
||||||
preview,
|
preview,
|
||||||
@@ -15,9 +15,9 @@ export function LetterItem({
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
function handleNavigate(): void {
|
function handleNavigate(): void {
|
||||||
if (status === "SEALED") {
|
if (status === "SEALED") {
|
||||||
navigate(ROUTES.READ(id));
|
navigate(PATHS.read(id));
|
||||||
} else {
|
} else {
|
||||||
navigate(ROUTES.WRITE(id));
|
navigate(PATHS.write(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Route PATTERNS
|
||||||
export const ROUTES = {
|
export const ROUTES = {
|
||||||
HOME: "/",
|
HOME: "/",
|
||||||
ONBOARD: "/onboard",
|
ONBOARD: "/onboard",
|
||||||
@@ -5,6 +6,13 @@ export const ROUTES = {
|
|||||||
ACTIVATE: "/activate/:uidb64/:token",
|
ACTIVATE: "/activate/:uidb64/:token",
|
||||||
LOGIN: "/login",
|
LOGIN: "/login",
|
||||||
DRAWER: "/drawer",
|
DRAWER: "/drawer",
|
||||||
WRITE: (public_id?: string) => `/quill/${public_id ? public_id : ""}`,
|
WRITE: "/quill/:public_id?", // ← static pattern
|
||||||
READ: (public_id?: string) => `/read/${public_id ? public_id : ""}`,
|
READ: "/read/:public_id",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Path BUILDERS
|
||||||
|
export const PATHS = {
|
||||||
|
write: (public_id?: string) => `/quill/${public_id ?? ""}`,
|
||||||
|
read: (public_id: string) => `/read/${public_id}`,
|
||||||
|
activate: (uidb64: string, token: string) => `/activate/${uidb64}/${token}`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import Logo from "../components/Logo";
|
import Logo from "../components/Logo";
|
||||||
import { DrawerSection } from "../components/ui/Drawer";
|
import { DrawerSection } from "../components/ui/Drawer";
|
||||||
import { LetterItem } from "../components/ui/LetterItem";
|
import { LetterItem } from "../components/ui/LetterItem";
|
||||||
import { ROUTES } from "../config/routes";
|
import { PATHS } from "../config/routes";
|
||||||
import { useAuth } from "../hooks/useAuth";
|
import { useAuth } from "../hooks/useAuth";
|
||||||
import { useLetters } from "../hooks/useLetters";
|
import { useLetters } from "../hooks/useLetters";
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ export default function Drawer() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="group mt-15 z-10 bg-transparent border border-dashed border-base-content/10 px-8 py-4 text-base-content/40 italic cursor-pointer transition-all hover:border-primary/40 hover:text-base-content/60 hover:bg-primary/5 hover:-translate-y-0.5 flex items-center gap-2 focus-visible:ring-2 focus-visible:ring-primary/50 duration-1000"
|
className="group mt-15 z-10 bg-transparent border border-dashed border-base-content/10 px-8 py-4 text-base-content/40 italic cursor-pointer transition-all hover:border-primary/40 hover:text-base-content/60 hover:bg-primary/5 hover:-translate-y-0.5 flex items-center gap-2 focus-visible:ring-2 focus-visible:ring-primary/50 duration-1000"
|
||||||
onClick={() => navigate(ROUTES.WRITE(""), { replace: true })}
|
onClick={() => navigate(PATHS.write(""), { replace: true })}
|
||||||
>
|
>
|
||||||
<FeatherIcon
|
<FeatherIcon
|
||||||
size={18}
|
size={18}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
} from "../components/ui/ComposeCanvas";
|
} from "../components/ui/ComposeCanvas";
|
||||||
import DateDisplay from "../components/ui/DateDisplay";
|
import DateDisplay from "../components/ui/DateDisplay";
|
||||||
import { endpoints } from "../config/endpoints";
|
import { endpoints } from "../config/endpoints";
|
||||||
import { ROUTES } from "../config/routes";
|
import { PATHS } from "../config/routes";
|
||||||
import { useKeyStore } from "../store/useKeyStore";
|
import { useKeyStore } from "../store/useKeyStore";
|
||||||
import { CryptoUtils } from "../utils/crypto";
|
import { CryptoUtils } from "../utils/crypto";
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ export default function Editor() {
|
|||||||
if (!public_id && !letterIdRef.current) {
|
if (!public_id && !letterIdRef.current) {
|
||||||
// if no uuid slug, then generate a new one and update params
|
// if no uuid slug, then generate a new one and update params
|
||||||
letterIdRef.current = crypto.randomUUID();
|
letterIdRef.current = crypto.randomUUID();
|
||||||
navigate(ROUTES.WRITE(letterIdRef.current), { replace: true });
|
navigate(PATHS.write(letterIdRef.current), { replace: true });
|
||||||
} else if (public_id) {
|
} else if (public_id) {
|
||||||
letterIdRef.current = public_id;
|
letterIdRef.current = public_id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user