1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
import { useEffect, useState } from "react";
import { NewsData, NewsFeed } from "../components/NewsFeed";
import { Link, useParams, useSearchParams } from "react-router-dom";
import { getGameTitle } from "../utils.ts";
import TitleBar from "../components/TitleBar";
import { GameNotes } from "../components/GameNotes";
import NotificationButton from "../components/NotificationButton";
import { useTranslation } from "react-i18next";
interface ArcadeNewsAPIData {
fetch_time: number;
news_posts: Array<NewsData>;
}
export default function Home() {
const { t } = useTranslation();
const { gameId } = useParams<{ gameId?: string }>();
const [searchParams] = useSearchParams();
const isMoe = searchParams.has("moe");
const rssFeedUrl =
import.meta.env.VITE_NEWS_BASE_URL + "/" + gameId + "_news.xml";
const newsAPIBase = import.meta.env.VITE_NEWS_BASE_URL;
const [newsFeedData, setNewsFeedData] = useState<ArcadeNewsAPIData | null>(
null,
);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<boolean>(false);
const [subscribedGames, setSubscribedGames] = useState<string[]>([]);
const [showSubscribedDropdown, setShowSubscribedDropdown] = useState(false);
useEffect(() => {
// Load subscribed games from localStorage
const loadSubscribedGames = () => {
const topics = JSON.parse(
localStorage.getItem("subscribed_topics") || "[]",
);
setSubscribedGames(topics);
};
loadSubscribedGames();
// Listen for storage changes to update subscribed games list
const handleStorageChange = () => {
loadSubscribedGames();
};
window.addEventListener("storage", handleStorageChange);
return () => {
window.removeEventListener("storage", handleStorageChange);
};
}, []);
useEffect(() => {
const fetchNews = async () => {
setLoading(true);
setError(false);
const newsDataFileName = gameId ? `${gameId}_news.json` : "news.json";
try {
const response = await fetch(newsAPIBase + "/" + `${newsDataFileName}`);
if (!response.ok) {
throw new Error(`Failed to fetch news: ${response.statusText}`);
}
const data: ArcadeNewsAPIData = await response.json();
setNewsFeedData(data);
} catch (e) {
console.error(e);
setError(true);
} finally {
setLoading(false);
}
};
fetchNews();
}, [gameId, newsAPIBase]); // Re-fetch when gameId changes
// Update subscribed games when localStorage changes locally
useEffect(() => {
const checkSubscriptions = () => {
const topics = JSON.parse(
localStorage.getItem("subscribed_topics") || "[]",
);
setSubscribedGames(topics);
};
const interval = setInterval(checkSubscriptions, 500);
return () => clearInterval(interval);
}, []);
if (loading) {
return (
<>
<TitleBar />
<div
className={`flex items-center justify-center h-screen ${isMoe ? "bg-pink-100" : "bg-black"}`}
>
<div
className={`animate-spin rounded-full h-16 w-16 border-t-4 ${isMoe ? "border-pink-500" : "border-purple-600"}`}
></div>
</div>
</>
);
}
if (error || newsFeedData === null) {
return (
<>
<TitleBar />
<div
className={`${isMoe ? "bg-pink-100" : "bg-gray-950"} min-h-screen flex items-center justify-center`}
>
<div className="text-center px-4">
<div
className={`${isMoe ? "text-pink-500" : "text-purple-500"} text-8xl font-bold mb-4`}
>
404
</div>
<h1
className={`${isMoe ? "text-pink-900" : "text-white"} text-3xl font-bold mb-4`}
>
{t('news_not_found')}
</h1>
<p
className={`${isMoe ? "text-pink-700" : "text-gray-400"} text-lg mb-8`}
>
{gameId
? `Unable to fetch news for ${getGameTitle(gameId)}`
: "Unable to fetch news feed"}
</p>
<div
className={`${isMoe ? "bg-pink-200" : "bg-gray-800"} rounded-lg p-6 max-w-md mx-auto`}
>
<p
className={`${isMoe ? "text-pink-800" : "text-gray-300"} mb-4`}
>
The news feed you're looking for might be temporarily
unavailable or doesn't exist.
</p>
<a
href="/"
className={`inline-block px-6 py-3 rounded-lg font-semibold transition-colors ${
isMoe
? "bg-pink-500 text-white hover:bg-pink-600"
: "bg-purple-600 text-white hover:bg-purple-700"
}`}
>
{t('return_home')}
</a>
</div>
</div>
</div>
</>
);
}
return (
<>
<TitleBar />
<div
className={`${isMoe ? "bg-pink-100 text-pink-900 font-[Zen_Maru_Gothic]" : "bg-gray-950"} min-h-screen py-6`}
>
<div className="max-w-[600px] mx-auto px-4">
{gameId ? (
<div
className={`${isMoe ? "bg-pink-200 text-pink-900" : "bg-gray-800 text-white"} rounded-lg p-6 text-center shadow-lg`}
>
<h1 className="text-2xl font-bold mb-2">
{getGameTitle(gameId)} News
</h1>
{GameNotes(isMoe)[gameId] && (
<div className="text-left">{GameNotes(isMoe)[gameId]}</div>
)}
<div className="mt-4">
{gameId !== "rb_deluxe_plus" && (
<NotificationButton gameId={gameId} isMoe={isMoe} />
)}
</div>
<div className="mt-2">
<a
href={rssFeedUrl}
className={`inline-flex items-center gap-2 px-3 py-1.5 rounded-lg font-medium transition-colors ${
isMoe
? "bg-pink-300 text-pink-800 hover:bg-pink-400"
: "bg-gray-700 text-white hover:bg-gray-600"
}`}
>
<svg
fill="#FFFFFF"
height="24px"
width="24px"
version="1.1"
id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox="-271 273 256 256"
xmlSpace="preserve"
>
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g
id="SVGRepo_tracerCarrier"
stroke-linecap="round"
stroke-linejoin="round"
></g>
<g id="SVGRepo_iconCarrier">
{" "}
<g>
{" "}
<path d="M-271,360v48.9c31.9,0,62.1,12.6,84.7,35.2c22.6,22.6,35.1,52.8,35.1,84.8v0.1h49.1c0-46.6-19-88.7-49.6-119.4 C-182.2,379-224.4,360.1-271,360z"></path>{" "}
<path d="M-237,460.9c-9.4,0-17.8,3.8-24,10s-10,14.6-10,24c0,9.3,3.8,17.7,10,23.9c6.2,6.1,14.6,9.9,24,9.9s17.8-3.7,24-9.9 s10-14.6,10-23.9c0-9.4-3.8-17.8-10-24C-219.2,464.7-227.6,460.9-237,460.9z"></path>{" "}
<path d="M-90.1,348.1c-46.3-46.4-110.2-75.1-180.8-75.1v48.9C-156.8,322-64.1,414.9-64,529h49C-15,458.4-43.7,394.5-90.1,348.1z"></path>{" "}
</g>{" "}
</g>
</svg>
RSS Feed
</a>
</div>
</div>
) : (
<>
<div
className={`${isMoe ? "bg-pink-200 text-pink-900" : "bg-gray-800 text-white"} rounded-lg p-6 text-center shadow-lg`}
>
<h1 className="text-2xl font-bold">{t('homepage.welcome')}</h1>
<h2
className={`text-2xl font-extrabold mb-4 tracking-widest text-center uppercase glow-neon ${
isMoe ? "text-pink-500" : "text-[#00FF00]"
}`}
>
SECOND STYLE
</h2>
<div className="floating">
<img
src="/liris.webp"
className="w-48 mx-auto mb-2 object-contain rounded-2xl"
/>
</div>
<p>
{t('homepage.news_aggregation_note')}
</p>
<p className="mt-2">
{t('homepage.rss_feeds')}
</p>
<p className="mt-2">
{t('homepage.github_info').split('GitHub')[0]}{" "}
<a
href="https://github.com/pinapelz/573-updates"
className="text-blue-500 hover:underline"
>
GitHub
</a>{" "}
{t('homepage.github_info').split('GitHub')[1] || ''}
</p>
<div className="mt-6">
<div className="mt-4">
<NotificationButton isMoe={isMoe} />
{/* Subscribed Games Display */}
{subscribedGames.length > 0 && (
<div className="mt-3">
<button
onClick={() =>
setShowSubscribedDropdown(!showSubscribedDropdown)
}
className={`text-sm ${
isMoe
? "text-pink-700 hover:text-pink-500"
: "text-gray-300 hover:text-white"
} flex items-center gap-1 mx-auto transition-colors`}
>
<span>
{`${t('subscribed_to_games_count')}`} {subscribedGames.length} {`${t('games')}`}
</span>
<svg
className={`w-4 h-4 transition-transform ${showSubscribedDropdown ? "rotate-180" : ""}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M19 9l-7 7-7-7"
/>
</svg>
</button>
{showSubscribedDropdown && (
<div
className={`mt-2 p-3 rounded-lg ${
isMoe
? "bg-pink-300 bg-opacity-50"
: "bg-gray-700 bg-opacity-50"
}`}
>
<div className="grid grid-cols-2 gap-2 text-sm">
{subscribedGames.map((gameId) => (
<Link
key={gameId}
to={`/game/${gameId}`}
className={`${
isMoe
? "text-pink-700 hover:text-pink-500 hover:bg-pink-200"
: "text-gray-300 hover:text-white hover:bg-gray-600"
} px-2 py-1 rounded transition-all`}
>
{getGameTitle(gameId)}
</Link>
))}
</div>
</div>
)}
</div>
)}
</div>
</div>
</div>
</>
)}
<NewsFeed newsItems={newsFeedData.news_posts} />
</div>
<footer
className={`mt-8 text-center text-sm ${isMoe ? "text-pink-800" : "text-gray-400"}`}
>
<p>
Last updated:{" "}
{new Date(newsFeedData.fetch_time * 1000).toLocaleString()}
</p>
<p>
<a
href="https://moekyun.me/"
className={`${isMoe ? "text-pink-600 hover:text-pink-400" : "hover:underline"}`}
>
a moekyun service
</a>
</p>
</footer>
</div>
</>
);
}
|