Skip to content

Commit

Permalink
♻️ refactor(books): Move hooks to /ui.
Browse files Browse the repository at this point in the history
To minimize server refreshes when developing.
  • Loading branch information
make-github-pseudonymous-again committed Jan 1, 2025
1 parent 68943e9 commit 097acd5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
11 changes: 0 additions & 11 deletions imports/api/books.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import addYears from 'date-fns/addYears';

import schema from '../lib/schema';

import makeQuery from './makeQuery';
import makeObservedQueryHook from './makeObservedQueryHook';
import {
type NormalizedLine,
normalizedLine,
Expand All @@ -13,17 +11,8 @@ import {
} from './string';

import {Books, collection} from './collection/books';
import {BooksCache} from './collection/books/cache';

import publication from './publication/books/find';
import cachePublication from './publication/books/observe';
import type TransactionDriver from './transaction/TransactionDriver';

export const useBooks = makeQuery(Books, publication);

// TODO rename to useObservedBooks
export const useBooksFind = makeObservedQueryHook(BooksCache, cachePublication);

const sanitizeInput = normalizedLineInput;
const sanitize = normalizedLine;

Expand Down
4 changes: 3 additions & 1 deletion imports/ui/books/BookRenamingDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import TagRenamingDialog from '../tags/TagRenamingDialog';

import rename from '../../api/endpoint/books/rename';

import {books, useBooksFind} from '../../api/books';
import {books} from '../../api/books';
import {type BookDocument} from '../../api/collection/books';

import useBooksFind from './useBooksFind';

type Props = {
readonly open: boolean;
readonly onClose: () => void;
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/books/BooksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import dateFormat from 'date-fns/format';

import TagList from '../tags/TagList';

import {useBooks} from '../../api/books';
import {useSettingCached} from '../settings/hooks';

import YearJumper from '../navigation/YearJumper';
Expand All @@ -17,6 +16,7 @@ import FixedFab from '../button/FixedFab';

import BookCard from './BookCard';
import BooksDownloadDialog from './BooksDownloadDialog';
import useBooks from './useBooks';

type Props = {
readonly type?: string;
Expand Down
7 changes: 7 additions & 0 deletions imports/ui/books/useBooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import makeQuery from '../../api/makeQuery';
import publication from '../../api/publication/books/find';
import {Books} from '../../api/collection/books';

const useBooks = makeQuery(Books, publication);

export default useBooks;
8 changes: 8 additions & 0 deletions imports/ui/books/useBooksFind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import makeObservedQueryHook from '../../api/makeObservedQueryHook';
import cachePublication from '../../api/publication/books/observe';
import {BooksCache} from '../../api/collection/books/cache';

// TODO: rename to useObservedBooks
const useBooksFind = makeObservedQueryHook(BooksCache, cachePublication);

export default useBooksFind;
3 changes: 2 additions & 1 deletion imports/ui/consultations/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import CircularProgress from '@mui/material/CircularProgress';
import TextField from '../input/TextField';

import useBookStats from '../books/useBookStats';
import {books, useBooksFind} from '../../api/books';
import {books} from '../../api/books';
import AutocompleteWithSuggestions from '../input/AutocompleteWithSuggestions';
import makeSubstringSuggestions from '../input/makeSubstringSuggestions';
import CurrencyAmountInput from '../input/CurrencyAmountInput';
import {parsePositiveIntegerStrictOrUndefined} from '../../api/string';
import useBooksFind from '../books/useBooksFind';

const useInBookNumberCollides = (
consultationId: string | undefined,
Expand Down

0 comments on commit 097acd5

Please sign in to comment.