Skip to content

Commit

Permalink
Merge pull request #104 from kitcc-org/103-fix-setUser-rule
Browse files Browse the repository at this point in the history
setUserの条件の書き換え
  • Loading branch information
Kosei805 authored Oct 29, 2024
2 parents dcf3470 + 94b6728 commit c1992c9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
30 changes: 14 additions & 16 deletions frontend/app/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 21 additions & 21 deletions frontend/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<getBooksResponse> => {
Expand All @@ -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;
}


Expand Down Expand Up @@ -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<createBookResponse> => {
Expand Down Expand Up @@ -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<getBookResponse> => {
Expand All @@ -234,7 +234,7 @@ export const getBook = async (bookId: string, options?: RequestInit): Promise<ge


export const getGetBookQueryKey = (bookId: string,) => {
return [`https://kitcc-library-api.kitcc.workers.dev/books/${bookId}`] as const;
return [`https://localhost:8787/books/${bookId}`] as const;
}


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<deleteBookResponse> => {
Expand Down Expand Up @@ -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<searchBooksResponse> => {
Expand All @@ -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;
}


Expand Down Expand Up @@ -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<getUsersResponse> => {
Expand All @@ -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;
}


Expand Down Expand Up @@ -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<createUserResponse> => {
Expand Down Expand Up @@ -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<getUserResponse> => {
Expand All @@ -683,7 +683,7 @@ export const getUser = async (userId: string, options?: RequestInit): Promise<ge


export const getGetUserQueryKey = (userId: string,) => {
return [`https://kitcc-library-api.kitcc.workers.dev/users/${userId}`] as const;
return [`https://localhost:8787/users/${userId}`] as const;
}


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<deleteUserResponse> => {
Expand Down Expand Up @@ -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<getLoansResponse> => {
Expand All @@ -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;
}


Expand Down Expand Up @@ -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<upsertLoansResponse> => {
Expand Down Expand Up @@ -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<loginResponse> => {
Expand Down Expand Up @@ -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<logoutResponse> => {
Expand Down

0 comments on commit c1992c9

Please sign in to comment.