Refactor: Extract nested ternaries into helper methods

Address code review feedback from Gemini Code Assist by extracting
complex nested ternary operators into dedicated helper methods:
- getSourceStatusText() for status text display
- getConnectionStatusTooltip() for tooltip text

This improves code readability and maintainability while matching
the existing patterns used throughout the RomM codebase (e.g.,
Personal.vue, GameInfo.vue).

No functional changes - all translation logic remains identical.
This commit is contained in:
Tanguy Mazé
2025-11-17 21:56:35 +01:00
parent 73dd0c965f
commit 29afff1d72

View File

@@ -96,6 +96,34 @@ async function fetchAllHeartbeats() {
});
}
// Helper function to get status text for a metadata source
function getSourceStatusText(source: { disabled: boolean; heartbeat?: boolean }) {
if (source.disabled) {
return t("scan.api-key-missing-short");
}
if (source.heartbeat === true) {
return t("scan.api-key-valid");
}
if (source.heartbeat === false) {
return t("scan.api-key-invalid");
}
return t("scan.connection-in-progress");
}
// Helper function to get tooltip text for connection status
function getConnectionStatusTooltip(source: { disabled: boolean; heartbeat?: boolean }) {
if (source.disabled) {
return t("scan.api-key-missing-or-disabled");
}
if (source.heartbeat === true) {
return t("scan.connection-successful");
}
if (source.heartbeat === false) {
return t("scan.connection-failed");
}
return t("scan.connection-in-progress");
}
onMounted(() => {
fetchAllHeartbeats();
});
@@ -127,15 +155,7 @@ onMounted(() => {
<div class="flex-grow-1">
<h3 class="text-h6 text-white">{{ source.name }}</h3>
<p class="text-caption text-grey-lighten-1 mb-0">
{{
source.disabled
? t("scan.api-key-missing-short")
: source.heartbeat === true
? t("scan.api-key-valid")
: source.heartbeat === false
? t("scan.api-key-invalid")
: t("scan.connection-in-progress")
}}
{{ getSourceStatusText(source) }}
</p>
</div>
</div>
@@ -161,7 +181,7 @@ onMounted(() => {
: 'warning'
"
size="large"
:title="source.disabled ? t('scan.api-key-missing-or-disabled') : source.heartbeat === true ? t('scan.connection-successful') : source.heartbeat === false ? t('scan.connection-failed') : t('scan.connection-in-progress')"
:title="getConnectionStatusTooltip(source)"
class="ml-4"
>
<v-icon>