mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-02 08:07:40 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
18
apps/web-react/app/features/layout/core/layout.server.ts
Normal file
18
apps/web-react/app/features/layout/core/layout.server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { AuthenticatedUser } from "~/features/auth/core/user.server";
|
||||
import { resolveSidebarData } from "~/features/sidebar/core/sidebar.server";
|
||||
import { GIT_COMMIT } from "~/utils/git-commit";
|
||||
|
||||
/**
|
||||
* The parts of the app shell that go stale on their own while a page sits open.
|
||||
* Served both by the root loader and by the resource route `LayoutDataProvider`
|
||||
* polls, so the two payloads can't drift apart. Notifications are not part of
|
||||
* this: they live in their own resource route refetched when skalop pings that
|
||||
* they changed (see `NotificationsProvider`).
|
||||
*/
|
||||
export async function resolveLayoutData(user: AuthenticatedUser | undefined) {
|
||||
return {
|
||||
loggedInUserId: user?.id ?? null,
|
||||
sidebar: await resolveSidebarData(user?.id ?? null),
|
||||
buildCommit: GIT_COMMIT,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { createCookieSessionStorage } from "react-router";
|
||||
import { ServerConfig } from "~/config.server";
|
||||
import { IS_E2E_TEST_RUN } from "~/utils/e2e";
|
||||
|
||||
const TEN_YEARS_IN_SECONDS = 315_360_000;
|
||||
|
||||
const sidenavStorage = createCookieSessionStorage({
|
||||
cookie: {
|
||||
name: "sidenav",
|
||||
secure: ServerConfig.isProduction && !IS_E2E_TEST_RUN,
|
||||
secrets: [ServerConfig.sessionSecret],
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
httpOnly: true,
|
||||
maxAge: TEN_YEARS_IN_SECONDS,
|
||||
},
|
||||
});
|
||||
|
||||
export async function getSidenavSession(request: Request) {
|
||||
const session = await sidenavStorage.getSession(
|
||||
request.headers.get("Cookie"),
|
||||
);
|
||||
return {
|
||||
getCollapsed: () => session.get("collapsed") === true,
|
||||
setCollapsed: (collapsed: boolean) => session.set("collapsed", collapsed),
|
||||
commit: () => sidenavStorage.commitSession(session),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user