fix: startup settings not visible on hard page refresh/direct load (#4100)

* fix: startup settings not visible on hard page refresh/direct load

* refactor: const func => named
This commit is contained in:
IMB11 2025-08-01 22:22:22 +01:00 committed by GitHub
parent 82d86839c7
commit b33e12c71d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,7 +42,7 @@
</label> </label>
<ButtonStyled> <ButtonStyled>
<button <button
:disabled="invocation === startupSettings?.original_invocation" :disabled="invocation === originalInvocation"
class="!w-full sm:!w-auto" class="!w-full sm:!w-auto"
@click="resetToDefault" @click="resetToDefault"
> >
@ -120,8 +120,9 @@ const props = defineProps<{
server: ModrinthServer; server: ModrinthServer;
}>(); }>();
await props.server.startup.fetch();
const data = computed(() => props.server.general); const data = computed(() => props.server.general);
const startupSettings = computed(() => props.server.startup);
const showAllVersions = ref(false); const showAllVersions = ref(false);
const jdkVersionMap = [ const jdkVersionMap = [
@ -137,33 +138,15 @@ const jdkBuildMap = [
{ value: "graal", label: "GraalVM" }, { value: "graal", label: "GraalVM" },
]; ];
const invocation = ref(""); const invocation = ref(props.server.startup.invocation);
const jdkVersion = ref(""); const jdkVersion = ref(
const jdkBuild = ref(""); jdkVersionMap.find((v) => v.value === props.server.startup.jdk_version)?.label,
const originalInvocation = ref("");
const originalJdkVersion = ref("");
const originalJdkBuild = ref("");
watch(
startupSettings,
(newSettings) => {
if (newSettings) {
invocation.value = newSettings.invocation;
originalInvocation.value = newSettings.invocation;
const jdkVersionLabel =
jdkVersionMap.find((v) => v.value === newSettings.jdk_version)?.label || "";
jdkVersion.value = jdkVersionLabel;
originalJdkVersion.value = jdkVersionLabel;
const jdkBuildLabel = jdkBuildMap.find((v) => v.value === newSettings.jdk_build)?.label || "";
jdkBuild.value = jdkBuildLabel;
originalJdkBuild.value = jdkBuildLabel;
}
},
{ immediate: true },
); );
const jdkBuild = ref(jdkBuildMap.find((v) => v.value === props.server.startup.jdk_build)?.label);
const originalInvocation = ref(invocation.value);
const originalJdkVersion = ref(jdkVersion.value);
const originalJdkBuild = ref(jdkBuild.value);
const hasUnsavedChanges = computed( const hasUnsavedChanges = computed(
() => () =>
@ -195,7 +178,7 @@ const displayedJavaVersions = computed(() => {
return showAllVersions.value ? jdkVersionMap.map((v) => v.label) : compatibleJavaVersions.value; return showAllVersions.value ? jdkVersionMap.map((v) => v.label) : compatibleJavaVersions.value;
}); });
const saveStartup = async () => { async function saveStartup() {
try { try {
isUpdating.value = true; isUpdating.value = true;
const invocationValue = invocation.value ?? ""; const invocationValue = invocation.value ?? "";
@ -232,17 +215,17 @@ const saveStartup = async () => {
} finally { } finally {
isUpdating.value = false; isUpdating.value = false;
} }
}; }
const resetStartup = () => { function resetStartup() {
invocation.value = originalInvocation.value; invocation.value = originalInvocation.value;
jdkVersion.value = originalJdkVersion.value; jdkVersion.value = originalJdkVersion.value;
jdkBuild.value = originalJdkBuild.value; jdkBuild.value = originalJdkBuild.value;
}; }
const resetToDefault = () => { function resetToDefault() {
invocation.value = startupSettings.value?.original_invocation ?? ""; invocation.value = originalInvocation.value ?? "";
}; }
</script> </script>
<style scoped> <style scoped>