Skip to content

Commit 22956df

Browse files
committed
refactor(web): move router utils to hoc folder
1 parent fd30f13 commit 22956df

File tree

9 files changed

+13
-11
lines changed

9 files changed

+13
-11
lines changed

apps/web/src/utils/router/guest.tsx renamed to apps/web/src/hoc/session/guest.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createAsync, Navigate, type RouteSectionProps, useSearchParams } from "
22
import { JSX, Match, Switch } from "solid-js";
33
import { getIsLoggedIn } from "~/lib/session";
44

5-
export function guest(children: (props: RouteSectionProps) => JSX.Element, fallback: string = "/settings") {
5+
export default function guest(children: (props: RouteSectionProps) => JSX.Element, fallback: string = "/settings") {
66
return (props: RouteSectionProps) => {
77
const [params] = useSearchParams();
88
const redirect = params.redirect;

apps/web/src/hoc/session/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import guest from "./guest";
2+
import protect from "./protect";
3+
4+
export { guest, protect };

apps/web/src/utils/router/protect.tsx renamed to apps/web/src/hoc/session/protect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createAsync, Navigate, type RouteSectionProps } from "@solidjs/router";
22
import { JSX, Match, Switch } from "solid-js";
33
import { getIsLoggedIn } from "~/lib/session";
44

5-
export function protect(children: (props: RouteSectionProps) => JSX.Element, fallback: string = "/login") {
5+
export default function protect(children: (props: RouteSectionProps) => JSX.Element, fallback: string = "/login") {
66
return (props: RouteSectionProps) => {
77
const redirect = encodeURIComponent(props.location.pathname);
88
const isLoggedIn = createAsync(() => getIsLoggedIn(), { deferStream: true });

apps/web/src/routes/(app)/library/(library).tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Container, Heading, Stack } from "@quotepedia/solid";
22
import { EmojiPicker } from "~/components/emoji-picker/EmojiPicker";
3+
import { protect } from "~/hoc/session";
34
import { useTranslator } from "~/lib/i18n";
4-
import { protect } from "~/utils/router";
55

66
export default protect(() => {
77
const t = useTranslator();

apps/web/src/routes/(app)/settings/account/(account).tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Button, Container, Heading, NavigationBar } from "@quotepedia/solid";
1+
import { Button, Container, NavigationBar } from "@quotepedia/solid";
22
import { A } from "@solidjs/router";
3-
import { useScopedTranslator } from "~/lib/i18n";
4-
import { protect } from "~/utils/router";
53
import { AccountInfoSection, AccountSecuritySection } from "~/components/settings";
4+
import { protect } from "~/hoc/session";
5+
import { useScopedTranslator } from "~/lib/i18n";
66

77
export default protect(() => {
88
const t = useScopedTranslator("settings");

apps/web/src/routes/(app)/settings/account/update-email.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { UpdateEmailStepper } from "~/components/update-email";
2-
import { protect } from "~/utils/router";
2+
import { protect } from "~/hoc/session";
33

44
export default protect(() => {
55
return <UpdateEmailStepper />;

apps/web/src/routes/(app)/settings/account/update-password.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { UpdatePasswordStepper } from "~/components/update-password";
2-
import { protect } from "~/utils/router";
2+
import { protect } from "~/hoc/session";
33

44
export default protect(() => {
55
return <UpdatePasswordStepper />;

apps/web/src/routes/(auth).tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { RouteSectionProps } from "@solidjs/router";
2-
import { guest } from "~/utils/router";
2+
import { guest } from "~/hoc/session";
33

44
export default guest((props: RouteSectionProps) => {
55
return props.children;

apps/web/src/utils/router/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
export * from "./guest";
2-
export * from "./protect";
31
export * from "./query";
42
export * from "./utils";

0 commit comments

Comments
 (0)