Skip to content

Commit 711ee68

Browse files
committed
🎨 updated data loading to include notifications
1 parent 23bd93c commit 711ee68

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

js/dataLoader.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export async function fetchAllData() {
1212
try {
1313
await new Promise(r => setTimeout(r, 800));
1414

15-
const [filmsRes, seriesRes, collectionsRes] = await Promise.all([
15+
const [filmsRes, seriesRes, collectionsRes, notifsRes] = await Promise.all([
1616
fetch('data/films.json'),
1717
fetch('data/series.json'),
18-
fetch('data/collections.json')
18+
fetch('data/collections.json'),
19+
fetch('data/notifs.json'),
1920
]);
2021

2122
if (!filmsRes.ok || !seriesRes.ok) throw new Error("Erreur de chargement des fichiers JSON (Films/Séries)");
@@ -30,10 +31,15 @@ export async function fetchAllData() {
3031
console.warn("Fichier collections.json non trouvé ou vide.");
3132
}
3233

33-
return { films, series, collections };
34+
const notifs = notifsRes.ok ? await notifsRes.json() : [];
35+
if (!notifsRes.ok) {
36+
console.warn("Fichier notifs.json non trouvé ou vide.");
37+
}
38+
39+
return { films, series, collections, notifs };
3440
} catch (error) {
3541
console.error("Erreur Data Loader:", error);
36-
return { films: {}, series: {}, collections: {} };
42+
return { films: {}, series: {}, collections: {}, notifs: {} };
3743
}
3844
}
3945

js/main.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* @module main
55
*/
66

7-
import { fetchAllData, fetchNotifs } from './dataLoader.js';
7+
import { fetchAllData } from './dataLoader.js';
88
import { setupHero, renderHorizontalRow, renderGrid, renderNotifs, openDetails, closeDetails, playCurrentMedia, renderCollections } from './display.js';
99
import { playVideo, closeVideo, toggleNotifs, toggleMobileMenu, toggleMobileSearch, showLoader, hideLoader } from './utils.js';
1010

11-
let appData = { films: {}, series: {}, collections: {} };
11+
let appData = { films: {}, series: {}, collections: {}, notifs: {} };
1212
let currentView = 'home';
1313

1414
window.router = router;
@@ -29,8 +29,7 @@ document.addEventListener('DOMContentLoaded', async () => {
2929
const data = await fetchAllData();
3030
appData = data;
3131

32-
const notifs = await fetchNotifs();
33-
renderNotifs(notifs);
32+
renderNotifs(data.notifs);
3433

3534
initHero();
3635
populateFilters();

0 commit comments

Comments
 (0)