Attempt to fix note resizing with React keys and Muuri sync

This commit is contained in:
2026-01-24 19:52:13 +01:00
parent d59ec592eb
commit 8e35780717
48 changed files with 3369 additions and 279 deletions

View File

@@ -152,7 +152,7 @@ export async function getNotes(includeArchived = false) {
try {
const notes = await prisma.note.findMany({
where: {
where: {
userId: session.user.id,
...(includeArchived ? {} : { isArchived: false }),
},
@@ -177,9 +177,9 @@ export async function getArchivedNotes() {
try {
const notes = await prisma.note.findMany({
where: {
where: {
userId: session.user.id,
isArchived: true
isArchived: true
},
orderBy: { updatedAt: 'desc' }
})
@@ -226,8 +226,8 @@ export async function searchNotes(query: string, useSemantic: boolean = false, n
// Check if query exists in title, content, or any label
return title.includes(queryLower) ||
content.includes(queryLower) ||
labels.some((label: string) => label.toLowerCase().includes(queryLower));
content.includes(queryLower) ||
labels.some((label: string) => label.toLowerCase().includes(queryLower));
});
return filteredNotes.map(parseNote);
@@ -269,8 +269,8 @@ async function semanticSearch(query: string, userId: string, notebookId?: string
// Keyword match
const keywordMatch = title.includes(queryLower) ||
content.includes(queryLower) ||
labels.some((l: string) => l.toLowerCase().includes(queryLower));
content.includes(queryLower) ||
labels.some((l: string) => l.toLowerCase().includes(queryLower));
// Semantic match (if embedding available)
let semanticMatch = false;
@@ -455,6 +455,9 @@ export async function updateNote(id: string, data: {
if ('images' in data) updateData.images = data.images ? JSON.stringify(data.images) : null
if ('links' in data) updateData.links = data.links ? JSON.stringify(data.links) : null
if ('notebookId' in data) updateData.notebookId = data.notebookId
// Explicitly handle size to ensure it propagates
if ('size' in data && data.size) updateData.size = data.size
updateData.updatedAt = new Date()
const note = await prisma.note.update({
@@ -469,17 +472,22 @@ export async function updateNote(id: string, data: {
}
// IMPORTANT: Call revalidatePath to ensure UI updates
// Revalidate main page, the note itself, and both old and new notebook paths
revalidatePath('/')
revalidatePath(`/note/${id}`)
// BUT skip if only updating size (let optimistic UI handle it)
const isSizeOnlyUpdate = Object.keys(data).length === 1 && 'size' in data
// If notebook changed, revalidate both notebook paths
if (data.notebookId !== undefined && data.notebookId !== oldNotebookId) {
if (oldNotebookId) {
revalidatePath(`/notebook/${oldNotebookId}`)
}
if (data.notebookId) {
revalidatePath(`/notebook/${data.notebookId}`)
if (!isSizeOnlyUpdate) {
// Revalidate main page, the note itself, and both old and new notebook paths
revalidatePath('/')
revalidatePath(`/note/${id}`)
// If notebook changed, revalidate both notebook paths
if (data.notebookId !== undefined && data.notebookId !== oldNotebookId) {
if (oldNotebookId) {
revalidatePath(`/notebook/${oldNotebookId}`)
}
if (data.notebookId) {
revalidatePath(`/notebook/${data.notebookId}`)
}
}
}
@@ -517,10 +525,12 @@ export async function updateColor(id: string, color: string) { return updateNote
export async function updateLabels(id: string, labels: string[]) { return updateNote(id, { labels }) }
export async function removeFusedBadge(id: string) { return updateNote(id, { autoGenerated: null }) }
// Update note size with revalidation
// Update note size WITHOUT revalidation - client uses optimistic updates
export async function updateSize(id: string, size: 'small' | 'medium' | 'large') {
await updateNote(id, { size })
revalidatePath('/')
const result = await updateNote(id, { size })
return result
}
// Get all unique labels
@@ -711,7 +721,7 @@ export async function syncAllEmbeddings() {
await prisma.note.update({ where: { id: note.id }, data: { embedding: JSON.stringify(embedding) } })
updatedCount++;
}
} catch (e) {}
} catch (e) { }
}
return { success: true, count: updatedCount }
} catch (error: any) {