Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/components/moderation/past-paper-page-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type PastPaperPageEditorProps = {
};

type PageEditorDraftState = {
sourceKey: string;
propKey: string;
baseline: PdfPageEdits | null;
draft: PdfPageEdits | null;
};
Expand Down Expand Up @@ -156,34 +156,34 @@ export default function PastPaperPageEditor({
[normalizedSavedPageEdits, totalPages],
);
const [pageEditState, setPageEditState] = useState<PageEditorDraftState>({
sourceKey: normalizedSavedKey,
propKey: normalizedSavedKey,
baseline: normalizedSavedPageEdits,
draft: normalizedSavedPageEdits,
});
const [isOpen, setIsOpen] = useState(false);
const [saveError, setSaveError] = useState<string | null>(null);
const [isPending, startTransition] = useTransition();
const baselinePageEdits =
pageEditState.sourceKey === normalizedSavedKey
pageEditState.propKey === normalizedSavedKey
? pageEditState.baseline
: normalizedSavedPageEdits;
const draftPageEdits =
pageEditState.sourceKey === normalizedSavedKey
pageEditState.propKey === normalizedSavedKey
? pageEditState.draft
: normalizedSavedPageEdits;
const setDraftPageEdits = (nextDraft: PageEditsUpdate) => {
setPageEditState((currentState) => {
const currentBaseline =
currentState.sourceKey === normalizedSavedKey
currentState.propKey === normalizedSavedKey
? currentState.baseline
: normalizedSavedPageEdits;
const currentDraft =
currentState.sourceKey === normalizedSavedKey
currentState.propKey === normalizedSavedKey
? currentState.draft
: normalizedSavedPageEdits;

return {
sourceKey: normalizedSavedKey,
propKey: normalizedSavedKey,
baseline: currentBaseline,
draft:
typeof nextDraft === "function" ? nextDraft(currentDraft) : nextDraft,
Expand All @@ -197,7 +197,7 @@ export default function PastPaperPageEditor({
);

setPageEditState({
sourceKey: serializePdfPageEdits(normalizedNextPageEdits, totalPages),
propKey: normalizedSavedKey,
baseline: normalizedNextPageEdits,
draft: normalizedNextPageEdits,
});
Expand Down
8 changes: 4 additions & 4 deletions app/components/pdfviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type PdfViewerProps = {
};

type SavedPageEditsState = {
sourceKey: string;
propKey: string;
value: PdfPageEdits | null;
};

Expand Down Expand Up @@ -2016,7 +2016,7 @@ export default function PDFViewer({
const [isPdfDarkMode, setIsPdfDarkMode] = useState(false);
const [savedPageEditsState, setSavedPageEditsState] =
useState<SavedPageEditsState>({
sourceKey: normalizedInitialPageEditsKey,
propKey: normalizedInitialPageEditsKey,
value: normalizedInitialPageEdits,
});
const [bufferLifecycleState, dispatchBufferLifecycle] = useReducer(
Expand All @@ -2030,13 +2030,13 @@ export default function PDFViewer({
showSlowLoadFallback,
} = bufferLifecycleState;
const savedPageEdits =
savedPageEditsState.sourceKey === normalizedInitialPageEditsKey
savedPageEditsState.propKey === normalizedInitialPageEditsKey
? savedPageEditsState.value
: normalizedInitialPageEdits;
const setSavedPageEdits = (nextPageEdits: PdfPageEdits | null) => {
const normalizedNextPageEdits = normalizePdfPageEdits(nextPageEdits);
setSavedPageEditsState({
sourceKey: serializePdfPageEdits(normalizedNextPageEdits),
propKey: normalizedInitialPageEditsKey,
value: normalizedNextPageEdits,
});
};
Expand Down
4 changes: 2 additions & 2 deletions lib/data/note-detail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cacheLife, cacheTag } from "next/cache";
import { asc, eq } from "drizzle-orm";
import { and, asc, eq } from "drizzle-orm";
import { cache } from "react";
import { normalizeGcsUrl } from "@/lib/normalize-gcs-url";
import { course, db, note, noteToTag, tag, user } from "@/db";
Expand Down Expand Up @@ -28,7 +28,7 @@ const loadNoteDetail = cache(async (id: string) => {
.leftJoin(course, eq(note.courseId, course.id))
.leftJoin(noteToTag, eq(noteToTag.a, note.id))
.leftJoin(tag, eq(noteToTag.b, tag.id))
.where(eq(note.id, id))
.where(and(eq(note.id, id), eq(note.isClear, true)))
.orderBy(asc(tag.name));

const firstRow = rows[0];
Expand Down