From 9ac37803b32588930f716bdd8f032bf2f02c6e9e Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 30 Dec 2025 10:42:51 +0000 Subject: [PATCH 1/7] Add has_notes flag and update note handling in ROM schemas and components --- backend/endpoints/responses/rom.py | 11 ++ backend/endpoints/rom.py | 17 ++- .../__generated__/models/SimpleRomSchema.ts | 1 + .../src/components/common/Game/Card/Base.vue | 8 +- .../common/Game/Dialog/NoteDialog.vue | 112 ++++-------------- .../components/common/Game/VirtualTable.vue | 10 +- 6 files changed, 55 insertions(+), 104 deletions(-) diff --git a/backend/endpoints/responses/rom.py b/backend/endpoints/responses/rom.py index 5249f0cb8..0fb653fae 100644 --- a/backend/endpoints/responses/rom.py +++ b/backend/endpoints/responses/rom.py @@ -329,15 +329,26 @@ class SiblingRomSchema(BaseModel): class SimpleRomSchema(RomSchema): + has_notes: bool = False + @classmethod def from_orm_with_request(cls, db_rom: Rom, request: Request) -> SimpleRomSchema: + from handler.database import db_rom_handler + + user_id = request.user.id db_rom = cls.populate_properties(db_rom, request) + + # Check if user has any notes for this ROM + notes = db_rom_handler.get_rom_notes(rom_id=db_rom.id, user_id=user_id) + db_rom.has_notes = len(notes) > 0 # type: ignore + return cls.model_validate(db_rom) @classmethod def from_orm_with_factory(cls, db_rom: Rom) -> SimpleRomSchema: db_rom.rom_user = rom_user_schema_factory() # type: ignore db_rom.siblings = [] # type: ignore + db_rom.has_notes = False # type: ignore return cls.model_validate(db_rom) diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index 6997d0b7b..f6c84ca73 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -1483,7 +1483,22 @@ async def get_rom_notes( tags=tags, ) - return [UserNoteSchema.model_validate(note) for note in notes] + result = [] + for note in notes: + note_dict = { + "id": note.id, + "title": note.title, + "content": note.content, + "is_public": note.is_public, + "tags": note.tags, + "created_at": note.created_at, + "updated_at": note.updated_at, + "user_id": note.user_id, + "username": note.user.username, + } + result.append(UserNoteSchema.model_validate(note_dict)) + + return result @protected_route( diff --git a/frontend/src/__generated__/models/SimpleRomSchema.ts b/frontend/src/__generated__/models/SimpleRomSchema.ts index b55eb0970..2574a28aa 100644 --- a/frontend/src/__generated__/models/SimpleRomSchema.ts +++ b/frontend/src/__generated__/models/SimpleRomSchema.ts @@ -81,5 +81,6 @@ export type SimpleRomSchema = { rom_user: RomUserSchema; merged_screenshots: Array; merged_ra_metadata: (RomRAMetadata | null); + has_notes?: boolean; }; diff --git a/frontend/src/components/common/Game/Card/Base.vue b/frontend/src/components/common/Game/Card/Base.vue index 25d734988..04a6ebcba 100644 --- a/frontend/src/components/common/Game/Card/Base.vue +++ b/frontend/src/components/common/Game/Card/Base.vue @@ -154,12 +154,6 @@ const { forceBoxart: props.forceBoxart, }); -const hasNotes = computed(() => { - // TODO: Add note count to SimpleRom or check all_user_notes - // For now, return false until we implement proper note counting - return false; -}); - const computedAspectRatio = computed(() => { return galleryViewStore.getAspectRatio({ platformId: props.rom.platform_id, @@ -389,7 +383,7 @@ onBeforeUnmount(() => { mdi-star -import { MdPreview } from "md-editor-v3"; -import "md-editor-v3/lib/style.css"; import type { Emitter } from "mitt"; -import { inject, ref, computed } from "vue"; +import { inject, ref } from "vue"; import { useI18n } from "vue-i18n"; -import { useTheme } from "vuetify"; +import MultiNoteManager from "@/components/Details/MultiNoteManager.vue"; import RDialog from "@/components/common/RDialog.vue"; import romApi from "@/services/api/rom"; -import type { SimpleRom } from "@/stores/roms"; +import type { DetailedRom } from "@/stores/roms"; import type { Events } from "@/types/emitter"; -import { toBrowserLocale } from "@/utils"; -const theme = useTheme(); const emitter = inject>("emitter"); -const { t, locale } = useI18n(); +const { t } = useI18n(); -const rom = ref(null); +const rom = ref(null); const show = ref(false); -const notes = ref([]); const loading = ref(false); -// Computed to get current user notes -const currentUserNotes = computed(() => { - return notes.value - .filter((note) => note.user_id === rom.value?.rom_user?.user_id) - .sort((a, b) => a.title.localeCompare(b.title)); -}); - emitter?.on("showNoteDialog", async (romToShow) => { - rom.value = romToShow; show.value = true; + loading.value = true; - // Fetch notes for this ROM if (romToShow.id) { - loading.value = true; try { - const response = await romApi.getRomNotes({ romId: romToShow.id }); - notes.value = response.data; + const response = await romApi.getRom({ romId: romToShow.id }); + rom.value = response.data; } catch (error) { - console.error("Failed to fetch notes:", error); - notes.value = []; + console.error("Failed to fetch ROM details:", error); + rom.value = null; } finally { loading.value = false; } } }); +async function onNotesUpdated() { + if (rom.value?.id) { + try { + const updatedRom = await romApi.getRom({ romId: rom.value.id }); + // Update the rom with the new data + Object.assign(rom.value, updatedRom.data); + } catch (error) { + console.error("Failed to refetch ROM data:", error); + } + } +} + function closeDialog() { show.value = false; rom.value = null; - notes.value = []; } @@ -68,69 +65,8 @@ function closeDialog() { diff --git a/frontend/src/components/common/Game/VirtualTable.vue b/frontend/src/components/common/Game/VirtualTable.vue index 07796d57c..334e96f45 100644 --- a/frontend/src/components/common/Game/VirtualTable.vue +++ b/frontend/src/components/common/Game/VirtualTable.vue @@ -99,12 +99,6 @@ const HEADERS = [ const selectedRomIDs = computed(() => selectedRoms.value.map((rom) => rom.id)); -function hasNotes(item: SimpleRom): boolean { - // TODO: Add note count to SimpleRom or check all_user_notes - // For now, return false until we implement proper note counting - return false; -} - function showNoteDialog(event: MouseEvent | KeyboardEvent, item: SimpleRom) { event.preventDefault(); emitter?.emit("showNoteDialog", item); @@ -312,7 +306,7 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) { mdi-card-multiple-outline From 45d5d0e78c00b4499dc5ce2ee155a59ff60a6d68 Mon Sep 17 00:00:00 2001 From: Zurdi <34356590+zurdi15@users.noreply.github.com> Date: Tue, 30 Dec 2025 11:48:00 +0100 Subject: [PATCH 2/7] Update backend/endpoints/rom.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- backend/endpoints/rom.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index f6c84ca73..5b40629b9 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -1483,9 +1483,8 @@ async def get_rom_notes( tags=tags, ) - result = [] - for note in notes: - note_dict = { + return [ + UserNoteSchema.model_validate({ "id": note.id, "title": note.title, "content": note.content, @@ -1495,10 +1494,9 @@ async def get_rom_notes( "updated_at": note.updated_at, "user_id": note.user_id, "username": note.user.username, - } - result.append(UserNoteSchema.model_validate(note_dict)) - - return result + }) + for note in notes + ] @protected_route( From 500d2b6954d4e2d19b8b895a11e759ffb7dcecf1 Mon Sep 17 00:00:00 2001 From: Zurdi <34356590+zurdi15@users.noreply.github.com> Date: Tue, 30 Dec 2025 11:49:14 +0100 Subject: [PATCH 3/7] Update frontend/src/__generated__/models/SimpleRomSchema.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- frontend/src/__generated__/models/SimpleRomSchema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/__generated__/models/SimpleRomSchema.ts b/frontend/src/__generated__/models/SimpleRomSchema.ts index 2574a28aa..15b349e21 100644 --- a/frontend/src/__generated__/models/SimpleRomSchema.ts +++ b/frontend/src/__generated__/models/SimpleRomSchema.ts @@ -81,6 +81,6 @@ export type SimpleRomSchema = { rom_user: RomUserSchema; merged_screenshots: Array; merged_ra_metadata: (RomRAMetadata | null); - has_notes?: boolean; + has_notes: boolean; }; From 65efa5856fa0ce714efbe51d2ea572f981da6ab9 Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 30 Dec 2025 11:08:02 +0000 Subject: [PATCH 4/7] Refactor has_notes calculation and optimize note loading in ROM handling --- backend/endpoints/responses/rom.py | 11 ++++++----- backend/handler/database/roms_handler.py | 2 ++ .../src/components/common/Game/Dialog/NoteDialog.vue | 4 ---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/endpoints/responses/rom.py b/backend/endpoints/responses/rom.py index 0fb653fae..ad65dacd2 100644 --- a/backend/endpoints/responses/rom.py +++ b/backend/endpoints/responses/rom.py @@ -333,14 +333,15 @@ class SimpleRomSchema(RomSchema): @classmethod def from_orm_with_request(cls, db_rom: Rom, request: Request) -> SimpleRomSchema: - from handler.database import db_rom_handler - user_id = request.user.id db_rom = cls.populate_properties(db_rom, request) - # Check if user has any notes for this ROM - notes = db_rom_handler.get_rom_notes(rom_id=db_rom.id, user_id=user_id) - db_rom.has_notes = len(notes) > 0 # type: ignore + # Calculate has_notes from already-loaded notes relationship + # Check if there are any notes for this ROM (public or user's own) + notes = getattr(db_rom, "notes", []) + db_rom.has_notes = any( # type: ignore + note.is_public or note.user_id == user_id for note in notes + ) return cls.model_validate(db_rom) diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index 0b17cb07d..2d20e4b01 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -151,6 +151,8 @@ def with_simple(func): selectinload(Rom.sibling_roms).options( noload(Rom.platform), noload(Rom.metadatum) ), + # Load notes to avoid N+1 queries when checking for has_notes + selectinload(Rom.notes), ) return func(*args, **kwargs) diff --git a/frontend/src/components/common/Game/Dialog/NoteDialog.vue b/frontend/src/components/common/Game/Dialog/NoteDialog.vue index ac0975326..5031499ae 100644 --- a/frontend/src/components/common/Game/Dialog/NoteDialog.vue +++ b/frontend/src/components/common/Game/Dialog/NoteDialog.vue @@ -13,11 +13,9 @@ const { t } = useI18n(); const rom = ref(null); const show = ref(false); -const loading = ref(false); emitter?.on("showNoteDialog", async (romToShow) => { show.value = true; - loading.value = true; if (romToShow.id) { try { @@ -26,8 +24,6 @@ emitter?.on("showNoteDialog", async (romToShow) => { } catch (error) { console.error("Failed to fetch ROM details:", error); rom.value = null; - } finally { - loading.value = false; } } }); From b2c6590e82cd541448f557960d81c58cff91dff2 Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 30 Dec 2025 11:08:27 +0000 Subject: [PATCH 5/7] Merge remote-tracking branch 'origin/fix/notes-flag' --- frontend/src/__generated__/models/SimpleRomSchema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/__generated__/models/SimpleRomSchema.ts b/frontend/src/__generated__/models/SimpleRomSchema.ts index 2574a28aa..15b349e21 100644 --- a/frontend/src/__generated__/models/SimpleRomSchema.ts +++ b/frontend/src/__generated__/models/SimpleRomSchema.ts @@ -81,6 +81,6 @@ export type SimpleRomSchema = { rom_user: RomUserSchema; merged_screenshots: Array; merged_ra_metadata: (RomRAMetadata | null); - has_notes?: boolean; + has_notes: boolean; }; From 2c3397893f13a061883b940029eeab8afba85f20 Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 30 Dec 2025 11:12:32 +0000 Subject: [PATCH 6/7] Refactor note retrieval in get_rom_notes and update comment for notes loading in roms_handler --- backend/endpoints/rom.py | 15 +-------------- backend/handler/database/roms_handler.py | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index 5b40629b9..6997d0b7b 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -1483,20 +1483,7 @@ async def get_rom_notes( tags=tags, ) - return [ - UserNoteSchema.model_validate({ - "id": note.id, - "title": note.title, - "content": note.content, - "is_public": note.is_public, - "tags": note.tags, - "created_at": note.created_at, - "updated_at": note.updated_at, - "user_id": note.user_id, - "username": note.user.username, - }) - for note in notes - ] + return [UserNoteSchema.model_validate(note) for note in notes] @protected_route( diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index 2d20e4b01..5f20a6a7d 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -151,7 +151,7 @@ def with_simple(func): selectinload(Rom.sibling_roms).options( noload(Rom.platform), noload(Rom.metadatum) ), - # Load notes to avoid N+1 queries when checking for has_notes + # Show notes indicator on cards selectinload(Rom.notes), ) return func(*args, **kwargs) From a7bda9859afaeac16c90e5fe12e9a1a69fa75fd2 Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 30 Dec 2025 11:19:47 +0000 Subject: [PATCH 7/7] Make has_notes optional in SimpleRomSchema type definition --- frontend/src/__generated__/models/SimpleRomSchema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/__generated__/models/SimpleRomSchema.ts b/frontend/src/__generated__/models/SimpleRomSchema.ts index 15b349e21..2574a28aa 100644 --- a/frontend/src/__generated__/models/SimpleRomSchema.ts +++ b/frontend/src/__generated__/models/SimpleRomSchema.ts @@ -81,6 +81,6 @@ export type SimpleRomSchema = { rom_user: RomUserSchema; merged_screenshots: Array; merged_ra_metadata: (RomRAMetadata | null); - has_notes: boolean; + has_notes?: boolean; };