Refactor data loading to use static JSON imports
- Replaced dynamic fetch calls with direct imports of skill category and team data from JSON files for improved performance and reliability. - Removed obsolete JSON files from the public/data directory to clean up the codebase. - Updated loadSkillCategories and loadTeams functions to return imported data directly.
This commit is contained in:
@@ -1,42 +1,29 @@
|
||||
import { SkillCategory, Team } from "./types";
|
||||
|
||||
// Import direct des données JSON depuis le dossier /data
|
||||
import frontendData from "@/data/skills/frontend.json";
|
||||
import backendData from "@/data/skills/backend.json";
|
||||
import devopsData from "@/data/skills/devops.json";
|
||||
import mobileData from "@/data/skills/mobile.json";
|
||||
import dataData from "@/data/skills/data.json";
|
||||
import cloudData from "@/data/skills/cloud.json";
|
||||
import securityData from "@/data/skills/security.json";
|
||||
import designData from "@/data/skills/design.json";
|
||||
import teamsData from "@/data/teams.json";
|
||||
|
||||
export async function loadSkillCategories(): Promise<SkillCategory[]> {
|
||||
const categories = [
|
||||
"frontend",
|
||||
"backend",
|
||||
"devops",
|
||||
"mobile",
|
||||
"data",
|
||||
"cloud",
|
||||
"security",
|
||||
"design",
|
||||
];
|
||||
const skillCategories: SkillCategory[] = [];
|
||||
|
||||
for (const category of categories) {
|
||||
try {
|
||||
const response = await fetch(`/data/skills/${category}.json`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
skillCategories.push(data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Failed to load ${category} skills:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
return skillCategories;
|
||||
return [
|
||||
frontendData,
|
||||
backendData,
|
||||
devopsData,
|
||||
mobileData,
|
||||
dataData,
|
||||
cloudData,
|
||||
securityData,
|
||||
designData,
|
||||
] as SkillCategory[];
|
||||
}
|
||||
|
||||
export async function loadTeams(): Promise<Team[]> {
|
||||
try {
|
||||
const response = await fetch("/data/teams.json");
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
return data.teams;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to load teams:", error);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
return teamsData.teams as Team[];
|
||||
}
|
||||
Reference in New Issue
Block a user