From 7fe1e74b525fe826a92cef9cc9b334f99aefda96 Mon Sep 17 00:00:00 2001 From: ZestyTS Date: Wed, 18 Sep 2024 19:28:00 -0700 Subject: [PATCH] Added a js file that handles getting the json file for data, and updating the table's compatibility statuses --- src/services/compatibilityService.js | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/services/compatibilityService.js diff --git a/src/services/compatibilityService.js b/src/services/compatibilityService.js new file mode 100644 index 0000000..1920ce0 --- /dev/null +++ b/src/services/compatibilityService.js @@ -0,0 +1,43 @@ +import { useRoute } from 'vue-router'; + +// Function to fetch the JSON file dynamically based on the current route +export async function fetchCompatibilityData() { + const route = useRoute(); // Get the current route + const routeName = route.name || 'default'; // Use route name, fallback to 'default' + + const jsonUrl = `https://raw.githubusercontent.com/UWUVCI-PRIME/UWUVCI-Compatibility/main/${routeName}.json`; + + try { + // Fetch the JSON data + const response = await fetch(jsonUrl); + if (!response.ok) { + throw new Error(`Failed to fetch ${jsonFileName}`); + } + const data = await response.json(); + return data; + } catch (error) { + console.error('Error fetching compatibility data:', error); + return null; + } +} + +// Function to process and fix compatibility data +export function fixCompatibilityData(compatibilityData) { + if (!compatibilityData || !compatibilityData.compatibility) return; + + // Fix compatibility statuses and sort by game name + compatibilityData.compatibility.forEach((item) => { + if (item.status == 2) { + item.status = 'working'; + } else if (item.status == 1) { + item.status = 'issues'; + } else if (item.status == 0) { + item.status = 'broken'; + } + }); + + // Sort by game name + compatibilityData.compatibility.sort((a, b) => + a.game_name > b.game_name ? 1 : -1 + ); +}