fix: incorrect note id

This commit is contained in:
Lhcfl 2024-04-01 03:21:55 +08:00
parent cbe88c56ef
commit 9a0136514b
5 changed files with 29 additions and 16 deletions

View File

@ -2,7 +2,7 @@
<div <div
v-if="!muted.muted" v-if="!muted.muted"
v-show="!isDeleted" v-show="!isDeleted"
:id="appearNote.id" :id="appearNote.historyId || appearNote.id"
ref="el" ref="el"
v-hotkey="keymap" v-hotkey="keymap"
v-size="{ max: [500, 350] }" v-size="{ max: [500, 350] }"
@ -91,6 +91,9 @@
:style="{ :style="{
cursor: expandOnNoteClick && !detailedView ? 'pointer' : '', cursor: expandOnNoteClick && !detailedView ? 'pointer' : '',
}" }"
:class="{
history: appearNote.historyId,
}"
@contextmenu.stop="onContextmenu" @contextmenu.stop="onContextmenu"
@click="noteClick" @click="noteClick"
> >
@ -427,11 +430,13 @@ const keymap = {
s: () => showContent.value !== showContent.value, s: () => showContent.value !== showContent.value,
}; };
useNoteCapture({ if (!appearNote.value.historyId) {
rootEl: el, useNoteCapture({
note: appearNote, rootEl: el,
isDeletedRef: isDeleted, note: appearNote,
}); isDeletedRef: isDeleted,
});
}
function reply(viaKeyboard = false): void { function reply(viaKeyboard = false): void {
pleaseLogin(); pleaseLogin();
@ -864,6 +869,9 @@ defineExpose({
overflow: clip; overflow: clip;
padding: 20px 32px 10px; padding: 20px 32px 10px;
margin-top: -16px; margin-top: -16px;
&.history {
margin-top: -90px !important;
}
&:first-child, &:first-child,
&:nth-child(2) { &:nth-child(2) {

View File

@ -118,10 +118,9 @@ const emit = defineEmits<{
(ev: "status", error: boolean): void; (ev: "status", error: boolean): void;
}>(); }>();
interface Item { type Item = Endpoints[typeof props.pagination.endpoint]["res"] & {
id: string; id: string;
[another: string]: unknown; };
}
const rootEl = ref<HTMLElement>(); const rootEl = ref<HTMLElement>();
const items = ref<Item[]>([]); const items = ref<Item[]>([]);

View File

@ -8,5 +8,8 @@ export function notePage(
if (options?.historyPage) { if (options?.historyPage) {
return `/notes/${note.id}/history`; return `/notes/${note.id}/history`;
} }
if (note.historyId) {
return `/notes/${note.id}/history#${note.historyId}`
}
return `/notes/${note.id}`; return `/notes/${note.id}`;
}; };

View File

@ -10,21 +10,22 @@
<MkPagination <MkPagination
v-else v-else
ref="pagingComponent" ref="pagingComponent"
v-slot="{ items: noteEdits }" v-slot="{ items }: { items: NoteEdit[] }"
:pagination="pagination" :pagination="pagination"
> >
<div ref="tlEl" class="giivymft noGap"> <div ref="tlEl" class="giivymft noGap">
<XList <XList
v-slot="{ item: noteEdit }" v-slot="{item} : {item: Note}"
:items="convertNoteEditsToNotes(noteEdits as NoteEdit[])" :items="convertNoteEditsToNotes(items)"
class="notes" class="notes"
:no-gap="true" :no-gap="true"
> >
<XNote <XNote
:key="noteEdit.id" :key="item.id"
class="qtqtichx" class="qtqtichx"
:note="noteEdit" :note="item"
:hide-footer="true" :hide-footer="true"
:detailed-view="true"
/> />
</XList> </XList>
</div> </div>
@ -88,7 +89,7 @@ onMounted(() => {
function convertNoteEditsToNotes(noteEdits: NoteEdit[]) { function convertNoteEditsToNotes(noteEdits: NoteEdit[]) {
const now: NoteEdit = { const now: NoteEdit = {
id: note.value.id, id: "EditionNow",
noteId: note.value.id, noteId: note.value.id,
updatedAt: note.value.createdAt, updatedAt: note.value.createdAt,
text: note.value.text, text: note.value.text,
@ -99,7 +100,7 @@ function convertNoteEditsToNotes(noteEdits: NoteEdit[]) {
return [now].concat(noteEdits).map((noteEdit: NoteEdit, index, arr): Note => { return [now].concat(noteEdits).map((noteEdit: NoteEdit, index, arr): Note => {
return Object.assign({}, note.value, { return Object.assign({}, note.value, {
id: crypto.randomUUID(), // Don't use noteId historyId: noteEdit.id,
// Conversion from updatedAt to createdAt // Conversion from updatedAt to createdAt
// The createdAt of a edition's content is actually the updatedAt of the previous one. // The createdAt of a edition's content is actually the updatedAt of the previous one.
createdAt: arr[(index + 1) % arr.length].updatedAt, createdAt: arr[(index + 1) % arr.length].updatedAt,

View File

@ -174,6 +174,8 @@ export type Note = {
url?: string; url?: string;
updatedAt?: DateString; updatedAt?: DateString;
isHidden?: boolean; isHidden?: boolean;
/** if the note is a history */
historyId?: ID;
}; };
export type NoteEdit = { export type NoteEdit = {