🔄 Refactor async state management to simplify and streamline API calls in GamemasterManager component
This commit is contained in:
@@ -203,10 +203,7 @@ const {
|
|||||||
data: serverStatus,
|
data: serverStatus,
|
||||||
loading: statusLoading,
|
loading: statusLoading,
|
||||||
error: statusError
|
error: statusError
|
||||||
} = useAsyncState(async () => {
|
} = useAsyncState();
|
||||||
const response = await apiClient.get('/api/gamemaster/status');
|
|
||||||
return response;
|
|
||||||
}, null);
|
|
||||||
|
|
||||||
// Fetch gamemaster state
|
// Fetch gamemaster state
|
||||||
const {
|
const {
|
||||||
@@ -215,10 +212,7 @@ const {
|
|||||||
loading: gamemasterLoading,
|
loading: gamemasterLoading,
|
||||||
error: gamemasterError,
|
error: gamemasterError,
|
||||||
reset: resetGamemaster
|
reset: resetGamemaster
|
||||||
} = useAsyncState(async () => {
|
} = useAsyncState();
|
||||||
const data = await fetchLatestGamemaster();
|
|
||||||
return data;
|
|
||||||
}, null);
|
|
||||||
|
|
||||||
// Save to server state
|
// Save to server state
|
||||||
const {
|
const {
|
||||||
@@ -226,12 +220,7 @@ const {
|
|||||||
loading: saving,
|
loading: saving,
|
||||||
error: saveError,
|
error: saveError,
|
||||||
reset: resetSave
|
reset: resetSave
|
||||||
} = useAsyncState(async () => {
|
} = useAsyncState();
|
||||||
const result = await apiClient.post('/api/gamemaster/process', {});
|
|
||||||
// Reload server status after save
|
|
||||||
await loadServerStatus();
|
|
||||||
return result;
|
|
||||||
}, null);
|
|
||||||
|
|
||||||
// Process gamemaster data
|
// Process gamemaster data
|
||||||
const processedData = ref(null);
|
const processedData = ref(null);
|
||||||
@@ -251,13 +240,19 @@ const loading = computed(() => statusLoading.value || gamemasterLoading.value);
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// Load server status on component mount
|
// 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
|
// Replace manual loading state with async function
|
||||||
async function fetchGamemaster() {
|
async function fetchGamemaster() {
|
||||||
resetGamemaster();
|
resetGamemaster();
|
||||||
await fetchGamemasterData();
|
await fetchGamemasterData(async () => {
|
||||||
|
const data = await fetchLatestGamemaster();
|
||||||
|
return data;
|
||||||
|
});
|
||||||
processedData.value = null;
|
processedData.value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +265,15 @@ function processGamemaster() {
|
|||||||
// Error handling through computed error state
|
// 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() {
|
async function saveToServer() {
|
||||||
if (!processedData.value) return;
|
if (!processedData.value) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user