🔄 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,
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user