refactor: update PlatformSchema to use display_name and improve type definitions

This commit is contained in:
zurdi
2024-12-25 11:57:14 +00:00
parent b24511c4f6
commit b4aa71c1b4
4 changed files with 15 additions and 13 deletions

View File

@@ -11,7 +11,7 @@ class PlatformSchema(BaseModel):
slug: str
fs_slug: str
rom_count: int
raw_name: str = Field(alias="name")
name: str
custom_name: str | None = None
igdb_id: int | None = None
sgdb_id: int | None = None
@@ -33,5 +33,5 @@ class PlatformSchema(BaseModel):
@computed_field # type: ignore
@property
def name(self) -> str:
return self.custom_name or self.raw_name
def display_name(self) -> str:
return self.custom_name or self.name

View File

@@ -10,8 +10,8 @@ export type PlatformSchema = {
slug: string;
fs_slug: string;
rom_count: number;
readonly name: string;
custom_name?: (string | null);
name: string;
custom_name: (string | null);
igdb_id?: (number | null);
sgdb_id?: (number | null);
moby_id?: (number | null);
@@ -26,5 +26,6 @@ export type PlatformSchema = {
aspect_ratio?: string;
created_at: string;
updated_at: string;
readonly display_name: string;
};

View File

@@ -15,6 +15,7 @@ import { storeToRefs } from "pinia";
import { computed, inject, ref, watch } from "vue";
import { useDisplay } from "vuetify";
import { useI18n } from "vue-i18n";
import type { Platform } from "@/stores/platforms";
// Props
const { t } = useI18n();
@@ -66,13 +67,13 @@ function toggleEditable() {
async function updatePlatform() {
if (!updatedPlatform.value) return;
const { data: platform } = await platformApi
await platformApi
.updatePlatform({
platform: updatedPlatform.value,
platform: updatedPlatform.value as Platform,
})
.then(({ data }) => {
.then(({ data: platform }) => {
emitter?.emit("snackbarShow", {
msg: data.msg,
msg: "Platform updated successfully",
icon: "mdi-check-bold",
color: "green",
});
@@ -140,7 +141,7 @@ watch(
if (aspectRatio) {
// Find the index of the aspect ratio option that matches the current aspect ratio
const defaultAspectRatio = aspectRatioOptions.value.findIndex(
(option) => option.name == aspectRatio
(option) => option.name == aspectRatio,
);
// If a matching aspect ratio option is found, update the selectedAspectRatio
if (defaultAspectRatio !== -1) {
@@ -148,7 +149,7 @@ watch(
}
}
},
{ immediate: true } // Execute the callback immediately with the current value
{ immediate: true }, // Execute the callback immediately with the current value
);
</script>
@@ -175,7 +176,7 @@ watch(
v-if="auth.scopes.includes('platforms.write')"
>
<div v-if="!isEditable" class="text-h5 font-weight-bold pl-0">
<span>{{ currentPlatform.name }}</span>
<span>{{ currentPlatform.display_name }}</span>
</div>
<div v-else>
<v-text-field

View File

@@ -42,7 +42,7 @@ withDefaults(defineProps<{ platform: Platform; rail?: boolean }>(), {
</template>
<v-row no-gutters
><v-col
><span class="text-body-1">{{ platform.name }}</span></v-col
><span class="text-body-1">{{ platform.display_name }}</span></v-col
></v-row
>
<v-row no-gutters>