Archived
fix: cleanup
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
} from "react";
|
||||
import type { Bookmark, CreateMarkerPayload, MarkerEntry, MarkersByBook } from "@/types";
|
||||
import * as annotationsApi from "@/api/annotations";
|
||||
import { bookmarkToMarkerEntry, groupMarkersByBook, sortMarkers } from "@/utils/markers";
|
||||
import { bookmarkToMarkerEntry, groupMarkersByBook, sortBookmarks } from "@/utils/markers";
|
||||
|
||||
interface AnnotationsState {
|
||||
bookmarks: Bookmark[];
|
||||
@@ -37,10 +37,7 @@ function annotationsReducer(
|
||||
case "FETCH_BOOKMARKS_START":
|
||||
return { ...state, bookmarksLoading: true, error: null };
|
||||
case "FETCH_BOOKMARKS_SUCCESS": {
|
||||
const sorted = [...action.payload].sort((a, b) => {
|
||||
if (a.chapter_index !== b.chapter_index) return a.chapter_index - b.chapter_index;
|
||||
return a.epub_cfi.localeCompare(b.epub_cfi);
|
||||
});
|
||||
const sorted = [...action.payload].sort(sortBookmarks);
|
||||
return { ...state, bookmarks: sorted, bookmarksLoading: false };
|
||||
}
|
||||
case "SET_ERROR":
|
||||
@@ -51,10 +48,7 @@ function annotationsReducer(
|
||||
bookmarks: state.bookmarks.filter((b) => b.id !== action.payload),
|
||||
};
|
||||
case "ADD_BOOKMARK": {
|
||||
const next = [...state.bookmarks, action.payload].sort((a, b) => {
|
||||
if (a.chapter_index !== b.chapter_index) return a.chapter_index - b.chapter_index;
|
||||
return a.epub_cfi.localeCompare(b.epub_cfi);
|
||||
});
|
||||
const next = [...state.bookmarks, action.payload].sort(sortBookmarks);
|
||||
return { ...state, bookmarks: next };
|
||||
}
|
||||
default:
|
||||
@@ -105,7 +99,7 @@ export function AnnotationsProvider({
|
||||
}, []);
|
||||
|
||||
const markers = useMemo(
|
||||
() => state.bookmarks.map(bookmarkToMarkerEntry).sort(sortMarkers),
|
||||
() => [...state.bookmarks].sort(sortBookmarks).map(bookmarkToMarkerEntry),
|
||||
[state.bookmarks],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user