From f9406721f1bdffcb93d1597bf35922e498d42911 Mon Sep 17 00:00:00 2001 From: imamiya-masaki Date: Thu, 3 Oct 2024 17:28:44 +0900 Subject: [PATCH 1/3] driver-provider --- frontend/app/routes/driver/driverProvider.tsx | 33 +++++++++++++++++++ frontend/app/routes/driver/route.tsx | 5 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 frontend/app/routes/driver/driverProvider.tsx diff --git a/frontend/app/routes/driver/driverProvider.tsx b/frontend/app/routes/driver/driverProvider.tsx new file mode 100644 index 00000000..3868cbd3 --- /dev/null +++ b/frontend/app/routes/driver/driverProvider.tsx @@ -0,0 +1,33 @@ +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>({}); + +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 ( + {children} + ); +}; + +export const useDriver = () => useContext(driverContext); diff --git a/frontend/app/routes/driver/route.tsx b/frontend/app/routes/driver/route.tsx index bed2db39..39e20a15 100644 --- a/frontend/app/routes/driver/route.tsx +++ b/frontend/app/routes/driver/route.tsx @@ -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" }]; @@ -11,7 +12,9 @@ export default function DriverLayout() { return (
- + + +
Date: Thu, 3 Oct 2024 17:29:19 +0900 Subject: [PATCH 2/3] =?UTF-8?q?user=5Fprovider=E3=81=AEaccess=5Ftoken?= =?UTF-8?q?=E3=82=92rename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/routes/client/userProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/routes/client/userProvider.tsx b/frontend/app/routes/client/userProvider.tsx index 2a33a5dd..455d12b7 100644 --- a/frontend/app/routes/client/userProvider.tsx +++ b/frontend/app/routes/client/userProvider.tsx @@ -12,7 +12,7 @@ const userContext = createContext>({}); 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; } From 3c42ea3e2a85f9ae1cd4178146ac5476894a4c6a Mon Sep 17 00:00:00 2001 From: imamiya-masaki Date: Thu, 3 Oct 2024 17:31:15 +0900 Subject: [PATCH 3/3] fmt --- frontend/app/routes/driver/driverProvider.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/app/routes/driver/driverProvider.tsx b/frontend/app/routes/driver/driverProvider.tsx index 3868cbd3..6e17abcc 100644 --- a/frontend/app/routes/driver/driverProvider.tsx +++ b/frontend/app/routes/driver/driverProvider.tsx @@ -26,7 +26,9 @@ export const DriverProvider = ({ children }: { children: ReactNode }) => { }; return ( - {children} + + {children} + ); };