-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a js file that handles getting the json file for data, and upda…
…ting the table's compatibility statuses
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |