Skip to content

Commit

Permalink
Merge pull request #14 from isucon/driver
Browse files Browse the repository at this point in the history
Driver
  • Loading branch information
imamiya-masaki authored Oct 3, 2024
2 parents 89cd5bc + 3c42ea3 commit fa3a815
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frontend/app/routes/client/userProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const userContext = createContext<Partial<User>>({});

export const UserProvider = ({ children }: { children: ReactNode }) => {
const [searchParams] = useSearchParams();
const accessToken = searchParams.get("access_token") ?? undefined;
const accessToken = searchParams.get("user_access_token") ?? undefined;
if (accessToken === undefined) {
return;
}
Expand Down
35 changes: 35 additions & 0 deletions frontend/app/routes/driver/driverProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useSearchParams } from "@remix-run/react";
import { ReactNode, createContext, useContext } from "react";

export type AccessToken = string;

type Driver = {
id: string;
name: string;
accessToken: AccessToken;
};
const driverContext = createContext<Partial<Driver>>({});

export const DriverProvider = ({ children }: { children: ReactNode }) => {
const [searchParams] = useSearchParams();
const accessToken = searchParams.get("driver_access_token") ?? undefined;
if (accessToken === undefined) {
return;
}
/**
* TODO: ログイン情報取得処理
*/
const fetchedValue: Driver = {
id: "fetched-id",
name: "fetched-name",
accessToken,
};

return (
<driverContext.Provider value={fetchedValue}>
{children}
</driverContext.Provider>
);
};

export const useDriver = () => useContext(driverContext);
5 changes: 4 additions & 1 deletion frontend/app/routes/driver/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { MetaFunction } from "@remix-run/node";
import { Outlet } from "@remix-run/react";
import { FooterNavigation } from "~/components/FooterNavigation";
import { CircleIcon } from "~/components/icon/circle";
import { DriverProvider } from "./driverProvider";

export const meta: MetaFunction = () => {
return [{ title: "ISUCON14" }, { name: "description", content: "isucon14" }];
Expand All @@ -11,7 +12,9 @@ export default function DriverLayout() {
return (
<div className="font-sans h-screen flex relative flex-col">
<div className="flex-1">
<Outlet />
<DriverProvider>
<Outlet />
</DriverProvider>
</div>
<FooterNavigation
navigationMenus={[
Expand Down

0 comments on commit fa3a815

Please sign in to comment.