Skip to content

Commit

Permalink
Merge pull request #326 from recogito/rs/notes-bugfix
Browse files Browse the repository at this point in the history
"Notes" Sidebar Bugfixes
  • Loading branch information
rsimon authored Dec 4, 2024
2 parents f82e13f + 1395c25 commit 97160f0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/components/Annotation/AnnotationCardSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export const AnnotationCardSection = (props: AnnotationCardSectionProps) => {
}
}, [annotation, comment, index, present, tags]);

const isMine = creator?.id === me.id;
// Note that 'me' being undefined caused problems in the past, so we're
// just being a little defensive here. Context: me is usually derived from
// the (initialized) Annotorious user, which means it will be undefined
// until annotations are loaded.
const isMine = creator?.id === me?.id;

// Comments are editable if they are mine, or I'm a layer admin
const canEdit = !isReadOnly && (isMine || props.policies?.get('layers').has('INSERT')) && !isProjectLocked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ export const DocumentNotes = (props: DocumentNotesProps) => {

const [channel, setChannel] = useState<RealtimeChannel | undefined>();

useEffect(() => {
if (embeddedNotes) setNotes(current => ([...current, ...embeddedNotes]));
}, [embeddedNotes]);

useEffect(() => {
if (documentLayerIds) {
fetchNotes(documentLayerIds)
.then(notes => setNotes(current => ([...current, ...notes])))
.then(notes => {
setNotes([...notes, ...(embeddedNotes || [])])
})
.catch(onError);

// Set up realtime channel
Expand Down Expand Up @@ -109,7 +107,7 @@ export const DocumentNotes = (props: DocumentNotesProps) => {
setChannel(undefined);
}
}
}, [documentLayerIds, props.present]);
}, [embeddedNotes, documentLayerIds, props.present]);

return (
<DocumentNotesContext.Provider value={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import type { SupabaseAnnotation } from '@recogito/annotorious-supabase';
import type { DocumentNote } from '../Types';

export type Sorter = (a: DocumentNote, b: DocumentNote) => number;

const Newest = (a: DocumentNote, b: DocumentNote) =>
b.created_at.getTime() - a.created_at.getTime();
const Newest = (a: DocumentNote | SupabaseAnnotation, b: DocumentNote | SupabaseAnnotation) => {
const createdA = 'created_at' in a ? a.created_at : a.target.created;
const createdB = 'created_at' in b ? b.created_at : b.target.created;
return createdA && createdB ? createdB.getTime() - createdA.getTime() : 0;
}

const Oldest = (a: DocumentNote, b: DocumentNote) =>
a.created_at.getTime() - b.created_at.getTime();
const Oldest = (a: DocumentNote | SupabaseAnnotation, b: DocumentNote | SupabaseAnnotation) => {
const createdA = 'created_at' in a ? a.created_at : a.target.created;
const createdB = 'created_at' in b ? b.created_at : b.target.created;
return createdA && createdB ? createdA.getTime() - createdB.getTime() : 0;
}

export const Sorting = { Newest, Oldest };
4 changes: 2 additions & 2 deletions src/pages/[lang]/projects/[project]/export/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ const exportForAssignment = async (
);
}

export const GET: APIRoute = async ({ params, cookies, url }) => {
export const GET: APIRoute = async ({ request, params, cookies, url }) => {
// Verify if the user is logged in
const supabase = await createSupabaseServerClient(cookies);
const supabase = await createSupabaseServerClient(request, cookies);

const projectId = params.project!;

Expand Down

0 comments on commit 97160f0

Please sign in to comment.