Skip to content

Commit

Permalink
Added a js file that handles getting the json file for data, and upda…
Browse files Browse the repository at this point in the history
…ting the table's compatibility statuses
  • Loading branch information
ZestyTS committed Sep 19, 2024
1 parent c7b0d36 commit 7fe1e74
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/services/compatibilityService.js
Original file line number Diff line number Diff line change
@@ -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
);
}

0 comments on commit 7fe1e74

Please sign in to comment.