aboutsummaryrefslogtreecommitdiffstats
path: root/site/src/pages/Homepage.tsx
blob: db658ca1e86ae9d17026b56b8209226261a60e4b (plain) (blame)
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
import { useEffect, useState } from "react";
import { NewsData, NewsFeed } from "../components/NewsFeed";
import { 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";

interface ArcadeNewsAPIData {
  fetch_time: number;
  news_posts: Array<NewsData>;
}

export default function Home() {
  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);

  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

  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`}
            >
              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"
                }`}
              >
                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-2">
                <a href={rssFeedUrl} className="text-blue-400 hover:underline">
                  Subscribe via RSS
                </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">Welcome to 573-UPDATES</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>
                  News and Information for various arcade games is aggregated
                  here!
                </p>
                <p className="mt-2">
                  RSS feeds are available on each game's individual page
                </p>
                <p className="mt-2">
                  Please see the{" "}
                  <a
                    href="https://github.com/pinapelz/573-updates"
                    className="text-blue-500 hover:underline"
                  >
                    GitHub
                  </a>{" "}
                  for API information
                </p>
                <div className="mt-6">
                  <details className="rounded-lg">
                    <summary
                      className={`cursor-pointer text-lg font-semibold ${
                        isMoe
                          ? "text-pink-700 hover:text-pink-500"
                          : "text-gray-300 hover:text-white"
                      }`}
                    >
                      Receive Notifications
                    </summary>
                    <div className="mt-4">
                      <NotificationButton isMoe={isMoe} />
                      <p className="mt-2">
                        Enables notifications for the main feed
                      </p>
                    </div>
                  </details>
                </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>
    </>
  );
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage