Skip to content

Commit

Permalink
Add bookAtom
Browse files Browse the repository at this point in the history
 (#92)
  • Loading branch information
kimurash committed Nov 4, 2024
1 parent 0d12853 commit 2303dce
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion frontend/app/components/books/BookCardHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Checkbox, Group } from '@mantine/core';
import { useAtom } from 'jotai';
import { selectedBooksAtom } from '~/stores/bookAtom';
import type { CartProps } from '~/stores/cartAtom';
import { selectedBooksAtom } from '~/stores/cartAtom';
import { userAtom } from '~/stores/userAtom';
import BookCardHeaderBadge from './BookCardHeaderBadge';

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/routes/home._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GetBooksParams } from 'client/client.schemas';
import { useAtom } from 'jotai';
import { useEffect } from 'react';
import BookListComponent from '~/components/books/BookListComponent';
import { selectedBooksAtom } from '~/stores/cartAtom';
import { selectedBooksAtom } from '~/stores/bookAtom';

interface LoaderData {
booksResponse: getBooksResponse;
Expand Down
10 changes: 10 additions & 0 deletions frontend/app/stores/bookAtom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { atom } from 'jotai';

export interface SelectedBookProps {
id: number;
stock: number;
}

// 選択された本を管理するAtom
// 生存時間: DOM(ページをリロードするまで)
export const selectedBooksAtom = atom<SelectedBookProps[]>([]);
5 changes: 0 additions & 5 deletions frontend/app/stores/cartAtom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { atom } from 'jotai';
import { atomWithStorage, createJSONStorage } from 'jotai/utils';

const storage = createJSONStorage<CartProps[]>(() => sessionStorage);
Expand All @@ -10,7 +9,3 @@ export interface CartProps {
// カートの中身を管理するAtom
// 生存時間: セッションストレージ(タブが閉じられるまで)
export const cartAtom = atomWithStorage<CartProps[]>('cart', [], storage);

// 選択された本を管理するAtom
// 生存時間: DOM(ページをリロードするまで)
export const selectedBooksAtom = atom<CartProps[]>([]);

0 comments on commit 2303dce

Please sign in to comment.