From 87a7f28cf8d752a22b8a3df59ea314e814763a5b Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Thu, 29 Jan 2026 04:30:07 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20Refactor=20async=20state=20manag?= =?UTF-8?q?ement=20to=20simplify=20and=20streamline=20API=20calls=20in=20G?= =?UTF-8?q?amemasterManager=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/GamemasterManager.vue | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/code/websites/pokedex.online/src/views/GamemasterManager.vue b/code/websites/pokedex.online/src/views/GamemasterManager.vue index aba3089..2b1f5b8 100644 --- a/code/websites/pokedex.online/src/views/GamemasterManager.vue +++ b/code/websites/pokedex.online/src/views/GamemasterManager.vue @@ -203,10 +203,7 @@ const { data: serverStatus, loading: statusLoading, error: statusError -} = useAsyncState(async () => { - const response = await apiClient.get('/api/gamemaster/status'); - return response; -}, null); +} = useAsyncState(); // Fetch gamemaster state const { @@ -215,10 +212,7 @@ const { loading: gamemasterLoading, error: gamemasterError, reset: resetGamemaster -} = useAsyncState(async () => { - const data = await fetchLatestGamemaster(); - return data; -}, null); +} = useAsyncState(); // Save to server state const { @@ -226,12 +220,7 @@ const { loading: saving, error: saveError, reset: resetSave -} = useAsyncState(async () => { - const result = await apiClient.post('/api/gamemaster/process', {}); - // Reload server status after save - await loadServerStatus(); - return result; -}, null); +} = useAsyncState(); // Process gamemaster data const processedData = ref(null); @@ -251,13 +240,19 @@ const loading = computed(() => statusLoading.value || gamemasterLoading.value); onMounted(async () => { // Load server status on component mount - await loadServerStatus(); + await loadServerStatus(async () => { + const response = await apiClient.get('/api/gamemaster/status'); + return response; + }); }); // Replace manual loading state with async function async function fetchGamemaster() { resetGamemaster(); - await fetchGamemasterData(); + await fetchGamemasterData(async () => { + const data = await fetchLatestGamemaster(); + return data; + }); processedData.value = null; } @@ -270,7 +265,15 @@ function processGamemaster() { // Error handling through computed error state } } - +async () => { + const result = await apiClient.post('/api/gamemaster/process', {}); + // Reload server status after save + await loadServerStatus(async () => { + const response = await apiClient.get('/api/gamemaster/status'); + return response; + }); + return result; + } async function saveToServer() { if (!processedData.value) return;