Add server status loading and saving functionality with improved error handling and UI updates

This commit is contained in:
2026-01-28 18:59:10 +00:00
parent e4ca6b392b
commit aae38d0353

View File

@@ -80,8 +80,8 @@
{{ saving ? 'Saving...' : '💾 Save All Files to Server' }} {{ saving ? 'Saving...' : '💾 Save All Files to Server' }}
</button> </button>
<div v-if="saveSuccess" class="success"> <div v-if="saveSuccess" class="success">
Files saved to server successfully! Other apps can now access Files saved to server successfully! Other apps can now access the
the data via the Gamemaster API. data via the Gamemaster API.
</div> </div>
</div> </div>
@@ -114,7 +114,11 @@
</p> </p>
<p><strong>Files Available:</strong> {{ serverStatus.totalFiles }}</p> <p><strong>Files Available:</strong> {{ serverStatus.totalFiles }}</p>
<div class="file-list"> <div class="file-list">
<div v-for="file in serverStatus.available" :key="file.filename" class="file-item"> <div
v-for="file in serverStatus.available"
:key="file.filename"
class="file-item"
>
<span class="file-name">{{ file.filename }}</span> <span class="file-name">{{ file.filename }}</span>
<span class="file-size">{{ file.sizeKb }} KB</span> <span class="file-size">{{ file.sizeKb }} KB</span>
</div> </div>
@@ -159,7 +163,7 @@
</template> </template>
<script setup> <script setup>
import { ref, computed } from 'vue'; import { ref, computed, onMounted } from 'vue';
import { import {
fetchLatestGamemaster, fetchLatestGamemaster,
breakUpGamemaster, breakUpGamemaster,
@@ -169,14 +173,33 @@ import {
const loading = ref(false); const loading = ref(false);
const error = ref(null); const error = ref(null);
const saving = ref(false);
const saveSuccess = ref(false);
const rawGamemaster = ref(null); const rawGamemaster = ref(null);
const processedData = ref(null); const processedData = ref(null);
const serverStatus = ref(null);
const stats = computed(() => { const stats = computed(() => {
if (!processedData.value) return null; if (!processedData.value) return null;
return getGamemasterStats(processedData.value); return getGamemasterStats(processedData.value);
}); });
onMounted(async () => {
// Load server status on component mount
await loadServerStatus();
});
async function loadServerStatus() {
try {
const response = await fetch('/api/gamemaster/status');
if (response.ok) {
serverStatus.value = await response.json();
}
} catch (err) {
console.error('Failed to load server status:', err);
}
}
async function fetchGamemaster() { async function fetchGamemaster() {
loading.value = true; loading.value = true;
error.value = null; error.value = null;
@@ -203,6 +226,42 @@ function processGamemaster() {
} }
} }
async function saveToServer() {
if (!processedData.value) return;
saving.value = true;
saveSuccess.value = false;
error.value = null;
try {
const response = await fetch('/api/gamemaster/save', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
pokemon: processedData.value.pokemon,
pokemonAllForms: processedData.value.pokemonAllForms,
moves: processedData.value.moves,
raw: rawGamemaster.value
})
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.error || 'Failed to save to server');
}
saveSuccess.value = true;
// Reload server status
await loadServerStatus();
} catch (err) {
error.value = `Failed to save to server: ${err.message}`;
} finally {
saving.value = false;
}
}
function downloadPokemon() { function downloadPokemon() {
downloadJson(processedData.value.pokemon, 'pokemon.json'); downloadJson(processedData.value.pokemon, 'pokemon.json');
} }
@@ -223,6 +282,12 @@ function downloadAll() {
setTimeout(() => downloadAllForms(), 500); setTimeout(() => downloadAllForms(), 500);
setTimeout(() => downloadMoves(), 1000); setTimeout(() => downloadMoves(), 1000);
} }
function formatDate(dateString) {
if (!dateString || dateString === 'Never') return 'Never';
return new Date(dateString).toLocaleString();
}
</script>
</script> </script>
<style scoped> <style scoped>