|
1 | | -/*import React, { useEffect } from "react"; |
2 | | -import { model } from "../model"; |
3 | | -
|
4 | 1 | /** |
5 | | - * Reads favs from URL hash query string and populates model.favourites |
6 | | -
|
7 | | -function SharedView() { |
8 | | - useEffect(() => { |
9 | | - const processFavouritesFromURL = () => { |
10 | | - const hash = window.location.hash; |
11 | | - const queryString = hash.includes("?") ? hash.split("?")[1] : ""; |
12 | | - const params = new URLSearchParams(queryString); |
13 | | - const favCodes = (params.get("favs") || "").split(",").filter(Boolean); |
14 | | -
|
15 | | - console.log("Parsed fav codes:", favCodes); |
16 | | -
|
17 | | - if (!model.courses || model.courses.length === 0) { |
18 | | - console.warn("Courses not yet loaded, waiting..."); |
19 | | - return; |
20 | | - } |
21 | | -
|
22 | | - console.log("Courses loaded. Processing shared favourites."); |
23 | | -
|
24 | | - const favCourses = favCodes |
25 | | - .map(code => model.getCourse(code)) |
26 | | - .filter(course => course !== undefined); |
27 | | -
|
28 | | - model.favourites = favCourses; |
29 | | -
|
30 | | - console.log("Updated model.favourites:", favCourses); |
31 | | - }; |
32 | | -
|
33 | | - const interval = setInterval(() => { |
34 | | - if (model.courses && model.courses.length > 0) { |
35 | | - processFavouritesFromURL(); |
36 | | - clearInterval(interval); // Stop polling once done |
37 | | - } |
38 | | - }, 200); // Poll every 200ms until courses are ready |
39 | | -
|
40 | | - return () => clearInterval(interval); |
41 | | - }, []); |
42 | | -
|
43 | | - return ( |
44 | | - <div className="text-center text-xl p-6 text-white"> |
45 | | - <p>This is a shared view of someone's favourite courses.</p> |
46 | | - <p>Click the <b>Favourites</b> button to see the list!</p> |
47 | | - </div> |
48 | | - ); |
49 | | -} |
50 | | -
|
51 | | -export default SharedView; |
52 | | -*/ |
| 2 | + * The SharedView processes a URL containing a favourite selection |
| 3 | + * and starts the main app with the given parameters. |
| 4 | + */ |
53 | 5 |
|
54 | 6 | import React, { useEffect } from "react"; |
55 | | -import MainAppLayout from "./App.jsx"; // or wherever it's defined |
| 7 | +import App from "./App.jsx"; |
56 | 8 |
|
57 | 9 | function SharedView({ model }) { |
58 | | - useEffect(() => { |
59 | | - const processFavouritesFromURL = () => { |
60 | | - const hash = window.location.hash; |
61 | | - const queryString = hash.includes("?") ? hash.split("?")[1] : ""; |
62 | | - const params = new URLSearchParams(queryString); |
63 | | - const favCodes = (params.get("favs") || "").split(",").filter(Boolean); |
| 10 | + useEffect(() => { |
| 11 | + const processFavouritesFromURL = () => { |
| 12 | + const hash = window.location.hash; |
| 13 | + const queryString = hash.includes("?") ? hash.split("?")[1] : ""; |
| 14 | + const params = new URLSearchParams(queryString); |
| 15 | + const favCodes = (params.get("favs") || "").split(",").filter(Boolean); |
64 | 16 |
|
65 | | - if (!model.courses || model.courses.length === 0) return; |
| 17 | + if (!model.courses || model.courses.length === 0) return; |
66 | 18 |
|
67 | | - const favCourses = favCodes |
68 | | - .map(code => model.getCourse(code)) |
69 | | - .filter(Boolean); |
| 19 | + const favCourses = favCodes |
| 20 | + .map((code) => model.getCourse(code)) |
| 21 | + .filter(Boolean); |
70 | 22 |
|
71 | | - model.favourites = favCourses; |
72 | | - }; |
| 23 | + model.favourites = favCourses; |
| 24 | + }; |
73 | 25 |
|
74 | | - const interval = setInterval(() => { |
75 | | - if (model.courses && model.courses.length > 0) { |
76 | | - processFavouritesFromURL(); |
77 | | - clearInterval(interval); |
78 | | - } |
79 | | - }, 200); |
| 26 | + const interval = setInterval(() => { |
| 27 | + if (model.courses && model.courses.length > 0) { |
| 28 | + processFavouritesFromURL(); |
| 29 | + clearInterval(interval); |
| 30 | + } |
| 31 | + }, 200); |
80 | 32 |
|
81 | | - return () => clearInterval(interval); |
82 | | - }, [model]); |
| 33 | + return () => clearInterval(interval); |
| 34 | + }, [model]); |
83 | 35 |
|
84 | | - return <MainAppLayout model={model} />; |
| 36 | + return <App model={model} />; |
85 | 37 | } |
86 | 38 |
|
87 | 39 | export default SharedView; |
0 commit comments