From bb520ef2f7e055914f5b6e1988594580946bba4b Mon Sep 17 00:00:00 2001 From: Kosei805 Date: Tue, 29 Oct 2024 17:31:51 +0900 Subject: [PATCH 1/2] fix-setUser-timing --- frontend/app/routes/home.tsx | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/frontend/app/routes/home.tsx b/frontend/app/routes/home.tsx index 94064c6e..7fa009d9 100644 --- a/frontend/app/routes/home.tsx +++ b/frontend/app/routes/home.tsx @@ -77,23 +77,21 @@ const Home = () => { const navigation = useNavigation(); useEffect(() => { - // そもそもここが呼ばれていない - if (userId) { - // CookieにユーザIDが存在する - if (!user) { - // 状態変数にユーザ情報が保存されていない - // ユーザ情報を取得するAPIを呼び出す - getUser(userId).then((response) => { - if (response.status === 200) { - setUser(response.data); - } - }); - } - } else { - setUser(undefined); - } - if (navigation.state === 'idle') { + if (userId) { + // CookieにユーザIDが存在する + if (!user) { + // 状態変数にユーザ情報が保存されていない + // ユーザ情報を取得するAPIを呼び出す + getUser(userId).then((response) => { + if (response.status === 200) { + setUser(response.data); + } + }); + } + } else { + setUser(undefined); + } if (success) { successNotification(success); } else if (error) { From 94b6728fea7d9a7cc2554a977cf7a5474a12d29e Mon Sep 17 00:00:00 2001 From: Kosei805 Date: Tue, 29 Oct 2024 17:32:07 +0900 Subject: [PATCH 2/2] remove prepare deploy --- frontend/client/client.ts | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/frontend/client/client.ts b/frontend/client/client.ts index b1e85846..814f6819 100644 --- a/frontend/client/client.ts +++ b/frontend/client/client.ts @@ -73,7 +73,7 @@ export const getGetBooksUrl = (params?: GetBooksParams,) => { } }); - return normalizedParams.size ? `https://kitcc-library-api.kitcc.workers.dev/books?${normalizedParams.toString()}` : `https://kitcc-library-api.kitcc.workers.dev/books` + return normalizedParams.size ? `https://localhost:8787/books?${normalizedParams.toString()}` : `https://localhost:8787/books` } export const getBooks = async (params?: GetBooksParams, options?: RequestInit): Promise => { @@ -90,7 +90,7 @@ export const getBooks = async (params?: GetBooksParams, options?: RequestInit): export const getGetBooksQueryKey = (params?: GetBooksParams,) => { - return [`https://kitcc-library-api.kitcc.workers.dev/books`, ...(params ? [params]: [])] as const; + return [`https://localhost:8787/books`, ...(params ? [params]: [])] as const; } @@ -148,7 +148,7 @@ export type createBookResponse = { export const getCreateBookUrl = () => { - return `https://kitcc-library-api.kitcc.workers.dev/books` + return `https://localhost:8787/books` } export const createBook = async (createBookBody: CreateBookBody, options?: RequestInit): Promise => { @@ -217,7 +217,7 @@ export type getBookResponse = { export const getGetBookUrl = (bookId: string,) => { - return `https://kitcc-library-api.kitcc.workers.dev/books/${bookId}` + return `https://localhost:8787/books/${bookId}` } export const getBook = async (bookId: string, options?: RequestInit): Promise => { @@ -234,7 +234,7 @@ export const getBook = async (bookId: string, options?: RequestInit): Promise { - return [`https://kitcc-library-api.kitcc.workers.dev/books/${bookId}`] as const; + return [`https://localhost:8787/books/${bookId}`] as const; } @@ -294,7 +294,7 @@ export type updateBookResponse = { export const getUpdateBookUrl = (bookId: string,) => { - return `https://kitcc-library-api.kitcc.workers.dev/books/${bookId}` + return `https://localhost:8787/books/${bookId}` } export const updateBook = async (bookId: string, @@ -364,7 +364,7 @@ export type deleteBookResponse = { export const getDeleteBookUrl = (bookId: string,) => { - return `https://kitcc-library-api.kitcc.workers.dev/books/${bookId}` + return `https://localhost:8787/books/${bookId}` } export const deleteBook = async (bookId: string, options?: RequestInit): Promise => { @@ -439,7 +439,7 @@ export const getSearchBooksUrl = (params?: SearchBooksParams,) => { } }); - return normalizedParams.size ? `https://kitcc-library-api.kitcc.workers.dev/books/search?${normalizedParams.toString()}` : `https://kitcc-library-api.kitcc.workers.dev/books/search` + return normalizedParams.size ? `https://localhost:8787/books/search?${normalizedParams.toString()}` : `https://localhost:8787/books/search` } export const searchBooks = async (params?: SearchBooksParams, options?: RequestInit): Promise => { @@ -456,7 +456,7 @@ export const searchBooks = async (params?: SearchBooksParams, options?: RequestI export const getSearchBooksQueryKey = (params?: SearchBooksParams,) => { - return [`https://kitcc-library-api.kitcc.workers.dev/books/search`, ...(params ? [params]: [])] as const; + return [`https://localhost:8787/books/search`, ...(params ? [params]: [])] as const; } @@ -522,7 +522,7 @@ export const getGetUsersUrl = (params?: GetUsersParams,) => { } }); - return normalizedParams.size ? `https://kitcc-library-api.kitcc.workers.dev/users?${normalizedParams.toString()}` : `https://kitcc-library-api.kitcc.workers.dev/users` + return normalizedParams.size ? `https://localhost:8787/users?${normalizedParams.toString()}` : `https://localhost:8787/users` } export const getUsers = async (params?: GetUsersParams, options?: RequestInit): Promise => { @@ -539,7 +539,7 @@ export const getUsers = async (params?: GetUsersParams, options?: RequestInit): export const getGetUsersQueryKey = (params?: GetUsersParams,) => { - return [`https://kitcc-library-api.kitcc.workers.dev/users`, ...(params ? [params]: [])] as const; + return [`https://localhost:8787/users`, ...(params ? [params]: [])] as const; } @@ -597,7 +597,7 @@ export type createUserResponse = { export const getCreateUserUrl = () => { - return `https://kitcc-library-api.kitcc.workers.dev/users` + return `https://localhost:8787/users` } export const createUser = async (createUserBody: CreateUserBody, options?: RequestInit): Promise => { @@ -666,7 +666,7 @@ export type getUserResponse = { export const getGetUserUrl = (userId: string,) => { - return `https://kitcc-library-api.kitcc.workers.dev/users/${userId}` + return `https://localhost:8787/users/${userId}` } export const getUser = async (userId: string, options?: RequestInit): Promise => { @@ -683,7 +683,7 @@ export const getUser = async (userId: string, options?: RequestInit): Promise { - return [`https://kitcc-library-api.kitcc.workers.dev/users/${userId}`] as const; + return [`https://localhost:8787/users/${userId}`] as const; } @@ -742,7 +742,7 @@ export type updateUserResponse = { export const getUpdateUserUrl = (userId: string,) => { - return `https://kitcc-library-api.kitcc.workers.dev/users/${userId}` + return `https://localhost:8787/users/${userId}` } export const updateUser = async (userId: string, @@ -812,7 +812,7 @@ export type deleteUserResponse = { export const getDeleteUserUrl = (userId: string,) => { - return `https://kitcc-library-api.kitcc.workers.dev/users/${userId}` + return `https://localhost:8787/users/${userId}` } export const deleteUser = async (userId: string, options?: RequestInit): Promise => { @@ -888,7 +888,7 @@ export const getGetLoansUrl = (params?: GetLoansParams,) => { } }); - return normalizedParams.size ? `https://kitcc-library-api.kitcc.workers.dev/loans?${normalizedParams.toString()}` : `https://kitcc-library-api.kitcc.workers.dev/loans` + return normalizedParams.size ? `https://localhost:8787/loans?${normalizedParams.toString()}` : `https://localhost:8787/loans` } export const getLoans = async (params?: GetLoansParams, options?: RequestInit): Promise => { @@ -905,7 +905,7 @@ export const getLoans = async (params?: GetLoansParams, options?: RequestInit): export const getGetLoansQueryKey = (params?: GetLoansParams,) => { - return [`https://kitcc-library-api.kitcc.workers.dev/loans`, ...(params ? [params]: [])] as const; + return [`https://localhost:8787/loans`, ...(params ? [params]: [])] as const; } @@ -963,7 +963,7 @@ export type upsertLoansResponse = { export const getUpsertLoansUrl = () => { - return `https://kitcc-library-api.kitcc.workers.dev/loans` + return `https://localhost:8787/loans` } export const upsertLoans = async (upsertLoansBodyItem: UpsertLoansBodyItem[], options?: RequestInit): Promise => { @@ -1033,7 +1033,7 @@ export type loginResponse = { export const getLoginUrl = () => { - return `https://kitcc-library-api.kitcc.workers.dev/auth` + return `https://localhost:8787/auth` } export const login = async (loginBody: LoginBody, options?: RequestInit): Promise => { @@ -1103,7 +1103,7 @@ export type logoutResponse = { export const getLogoutUrl = () => { - return `https://kitcc-library-api.kitcc.workers.dev/auth` + return `https://localhost:8787/auth` } export const logout = async ( options?: RequestInit): Promise => {