diff --git a/backend/endpoints/responses/rom.py b/backend/endpoints/responses/rom.py index 5249f0cb8..ad65dacd2 100644 --- a/backend/endpoints/responses/rom.py +++ b/backend/endpoints/responses/rom.py @@ -329,15 +329,27 @@ class SiblingRomSchema(BaseModel): class SimpleRomSchema(RomSchema): + has_notes: bool = False + @classmethod def from_orm_with_request(cls, db_rom: Rom, request: Request) -> SimpleRomSchema: + user_id = request.user.id db_rom = cls.populate_properties(db_rom, request) + + # 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) @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/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index 0b17cb07d..5f20a6a7d 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) ), + # Show notes indicator on cards + selectinload(Rom.notes), ) return func(*args, **kwargs) 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; - // 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 = []; - } finally { - loading.value = false; + console.error("Failed to fetch ROM details:", error); + rom.value = null; } } }); +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 +61,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