-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
27 additions
and
31 deletions.
There are no files selected for viewing
28 changes: 10 additions & 18 deletions
28
src/frontend/src/entities/note/lib/useNextDisplayOrder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
import { type NoteItem, noteApi } from '../api'; | ||
import { useMemo } from 'react'; | ||
import { type NoteItem } from '../api'; | ||
|
||
const getMaxDisplayOrder = (notes: NoteItem[]): number => | ||
notes.reduce( | ||
(maxOrder, note) => (note.displayOrder > maxOrder ? note.displayOrder : maxOrder), | ||
-1, | ||
export const useNextDisplayOrder = (notes: NoteItem[]): number => | ||
useMemo( | ||
() => | ||
notes.reduce( | ||
(maxOrder, note) => (note.displayOrder > maxOrder ? note.displayOrder : maxOrder), | ||
-1, | ||
) + 1, | ||
[notes], | ||
); | ||
|
||
export const useNextDisplayOrder = (date: string): number => { | ||
const { nextDisplayOrder } = noteApi.useNotesQuery( | ||
{ date }, | ||
{ | ||
selectFromResult: ({ data, isSuccess }) => ({ | ||
nextDisplayOrder: isSuccess ? getMaxDisplayOrder(data.notes) + 1 : 0, | ||
}), | ||
}, | ||
); | ||
|
||
return nextDisplayOrder; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters