/ linuxy / src / components / Storefront.tsx
Swadhin Biswas Ci/improve release notes (#41) · 8/28/2026
04d550f
465 lines · 16.1 KB
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
import { invoke } from "@tauri-apps/api/core";
import { Download, Search, Github, Globe, CheckCircle } from "lucide-react";
import React, { useState, useEffect } from "react";

interface StoreApp {
  name: string;
  description: string;
  authors?: { name: string }[];
  links?: { type: string; url: string }[];
  icons?: string[];
  github_url?: string;
  stargazers_count?: number;
  categories?: string[];
}

interface StorefrontProps {
  installedAppNames?: string[];
  onRefreshLibrary?: () => void;
}

const Storefront: React.FC<StorefrontProps> = ({ installedAppNames = [], onRefreshLibrary }) => {
  const [apps, setApps] = useState<StoreApp[]>([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<string | null>(null);
  const [searchTerm, setSearchTerm] = useState("");
  const [source, setSource] = useState<"appimagehub" | "github">("appimagehub");
  const [downloadingName, setDownloadingName] = useState<string | null>(null);

  useEffect(() => {
    fetchData();
  }, [source]);

  const fetchData = async () => {
    try {
      setLoading(true);
      setError(null);
      const controller = new AbortController();
      const timeout = setTimeout(() => controller.abort(), 15000);
      if (source === "appimagehub") {
        const response = await fetch("https://appimage.github.io/feed.json", {
          signal: controller.signal,
        });
        if (!response.ok) throw new Error("Failed to fetch AppImageHub data");
        const data = await response.json();
        setApps(data.items || []);
      } else {
        const response = await fetch(
          "https://api.github.com/search/repositories?q=topic:appimage&sort=stars&order=desc&per_page=100",
          { signal: controller.signal }
        );
        if (!response.ok) throw new Error("Failed to fetch GitHub data");
        const data = await response.json();
        const githubApps = data.items.map((item: any) => ({
          name: item.name,
          description: item.description,
          authors: [{ name: item.owner.login }],
          links: [{ type: "GitHub", url: item.html_url }],
          github_url: item.html_url,
          stargazers_count: item.stargazers_count,
          icons: [item.owner.avatar_url],
        }));
        setApps(githubApps);
      }
      clearTimeout(timeout);
    } catch (err: any) {
      console.error(err);
      if (err?.name === "AbortError") {
        setError("Request timed out. Check your internet connection.");
      } else {
        setError(String(err));
      }
    } finally {
      setLoading(false);
    }
  };

  const isInstalled = (appName: string) => {
    const lowerName = appName.toLowerCase().trim();
    return installedAppNames.some(
      (n) => n.toLowerCase().trim() === lowerName || lowerName.includes(n.toLowerCase().trim())
    );
  };

  const filteredApps = apps.filter(
    (app) =>
      app.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
      (app.description && app.description.toLowerCase().includes(searchTerm.toLowerCase()))
  );

  return (
    <div style={{ paddingBottom: "40px" }} className="animate-fade-in">
      <div
        style={{
          position: "sticky",
          top: "-24px",
          zIndex: 10,
          background: "var(--bg-glass)",
          backdropFilter: "blur(12px)",
          WebkitBackdropFilter: "blur(12px)",
          borderBottom: "1px solid var(--border-color)",
          margin: "-24px -24px 20px -24px",
          padding: "24px 24px 20px 24px",
        }}
      >
        <div
          style={{
            display: "flex",
            justifyContent: "space-between",
            alignItems: "center",
            flexWrap: "wrap",
            gap: "15px",
            marginBottom: "20px",
          }}
        >
          <div>
            <h2 style={{ color: "var(--text-primary)", margin: "0 0 6px 0" }}>
              Discover AppImages
            </h2>
            <p style={{ color: "var(--text-secondary)", margin: 0, fontSize: "14px" }}>
              {source === "appimagehub"
                ? "Browsing AppImageHub Official Catalog"
                : "Browsing Popular GitHub AppImage Projects"}
            </p>
          </div>
          <div
            style={{
              display: "flex",
              gap: "6px",
              background: "var(--bg-input)",
              padding: "4px",
              borderRadius: "8px",
              border: "1px solid var(--border-color)",
            }}
          >
            <button
              onClick={() => setSource("appimagehub")}
              style={{
                display: "flex",
                alignItems: "center",
                gap: "8px",
                padding: "7px 14px",
                border: "none",
                borderRadius: "6px",
                cursor: "pointer",
                fontSize: "13px",
                fontWeight: 600,
                background: source === "appimagehub" ? "var(--accent-color)" : "transparent",
                color: source === "appimagehub" ? "#fff" : "var(--text-primary)",
              }}
            >
              <Globe size={15} /> Hub Catalog
            </button>
            <button
              onClick={() => setSource("github")}
              style={{
                display: "flex",
                alignItems: "center",
                gap: "8px",
                padding: "7px 14px",
                border: "none",
                borderRadius: "6px",
                cursor: "pointer",
                fontSize: "13px",
                fontWeight: 600,
                background: source === "github" ? "var(--accent-color)" : "transparent",
                color: source === "github" ? "#fff" : "var(--text-primary)",
              }}
            >
              <Github size={15} /> GitHub Trending
            </button>
          </div>
        </div>

        <div style={{ position: "relative", maxWidth: "420px" }}>
          <Search
            size={18}
            style={{
              position: "absolute",
              left: "12px",
              top: "50%",
              transform: "translateY(-50%)",
              color: "var(--text-muted)",
            }}
          />
          <input
            type="text"
            placeholder="Search AppImages by name or keyword..."
            value={searchTerm}
            onChange={(e) => setSearchTerm(e.target.value)}
            style={{
              width: "100%",
              padding: "10px 14px 10px 40px",
              background: "var(--bg-input)",
              border: "1px solid var(--border-color)",
              borderRadius: "8px",
              color: "var(--text-primary)",
              fontSize: "14px",
              outline: "none",
            }}
          />
        </div>
      </div>

      {loading && (
        <div style={{ textAlign: "center", padding: "50px", color: "var(--text-secondary)" }}>
          <div
            style={{
              width: "32px",
              height: "32px",
              border: "3px solid var(--border-color)",
              borderTopColor: "var(--accent-color)",
              borderRadius: "50%",
              animation: "spin 1s linear infinite",
              margin: "0 auto 15px auto",
            }}
          />
          Fetching {source === "github" ? "GitHub projects" : "Hub catalog"}...
        </div>
      )}

      {error && (
        <div
          style={{
            color: "var(--danger-color)",
            padding: "16px 20px",
            background: "var(--danger-bg)",
            borderRadius: "10px",
            border: "1px solid var(--danger-color)",
            fontSize: "14px",
          }}
        >
          {error}
        </div>
      )}

      <div
        style={{
          display: "grid",
          gridTemplateColumns: "repeat(auto-fill, minmax(310px, 1fr))",
          gap: "20px",
        }}
      >
        {filteredApps.map((app, idx) => {
          const githubLink = app.links?.find(
            (l) => l.type.toLowerCase() === "github" || l.type.toLowerCase() === "homepage"
          );
          const downloadLink =
            app.links?.find((l) => l.type.toLowerCase() === "download") || githubLink;
          const installed = isInstalled(app.name);
          const isBusy = downloadingName === app.name;

          return (
            <div
              key={idx}
              className="app-card"
              style={{ padding: "20px", display: "flex", flexDirection: "column" }}
            >
              <div style={{ display: "flex", alignItems: "center", marginBottom: "15px" }}>
                {app.icons && app.icons.length > 0 ? (
                  <img
                    src={
                      app.icons[0].startsWith("http")
                        ? app.icons[0]
                        : `https://appimage.github.io/database/${app.icons[0]}`
                    }
                    alt={app.name}
                    style={{
                      width: "56px",
                      height: "56px",
                      marginRight: "15px",
                      objectFit: "contain",
                      borderRadius: "10px",
                      background: "var(--bg-input)",
                    }}
                  />
                ) : (
                  <div
                    style={{
                      width: "56px",
                      height: "56px",
                      background: "var(--bg-input)",
                      borderRadius: "10px",
                      marginRight: "15px",
                      display: "flex",
                      alignItems: "center",
                      justifyContent: "center",
                    }}
                  >
                    <Globe size={24} color="var(--text-muted)" />
                  </div>
                )}
                <div style={{ overflow: "hidden", flex: 1 }}>
                  <div
                    style={{
                      fontWeight: "bold",
                      fontSize: "17px",
                      whiteSpace: "nowrap",
                      overflow: "hidden",
                      textOverflow: "ellipsis",
                      color: "var(--text-primary)",
                    }}
                  >
                    {app.name}
                  </div>
                  <div
                    style={{
                      fontSize: "12px",
                      color: "var(--text-secondary)",
                      display: "flex",
                      alignItems: "center",
                      gap: "6px",
                      marginTop: "4px",
                    }}
                  >
                    {source === "github" && <Github size={12} />}
                    <span>{app.authors?.[0]?.name || "Community"}</span>
                    {app.stargazers_count !== undefined && (
                      <span style={{ color: "#e3b341", fontWeight: 600 }}>
                        ★ {app.stargazers_count}
                      </span>
                    )}
                  </div>
                </div>
              </div>

              <div
                style={{
                  fontSize: "13px",
                  color: "var(--text-secondary)",
                  marginBottom: "18px",
                  flex: 1,
                  overflow: "hidden",
                  display: "-webkit-box",
                  WebkitLineClamp: 3,
                  WebkitBoxOrient: "vertical",
                  lineHeight: "1.5",
                }}
              >
                {app.description || "No description available for this project."}
              </div>

              <div style={{ display: "flex", gap: "10px", marginTop: "auto" }}>
                {installed ? (
                  <div
                    style={{
                      flex: 1,
                      background: "var(--accent-bg)",
                      color: "var(--accent-color)",
                      border: "1px solid var(--accent-color)",
                      padding: "10px",
                      borderRadius: "6px",
                      display: "flex",
                      alignItems: "center",
                      justifyContent: "center",
                      fontWeight: "bold",
                      fontSize: "13px",
                      gap: "6px",
                    }}
                  >
                    <CheckCircle size={16} /> Installed
                  </div>
                ) : (
                  <button
                    disabled={(!downloadLink && source !== "github") || isBusy}
                    onClick={async () => {
                      try {
                        setDownloadingName(app.name);
                        if (source === "github" && app.github_url) {
                          const parts = app.github_url.split("/");
                          const owner = parts[parts.length - 2];
                          const repo = parts[parts.length - 1];
                          const res = await fetch(
                            `https://api.github.com/repos/${owner}/${repo}/releases/latest`
                          );
                          const release = await res.json();
                          const asset = release.assets?.find((a: any) =>
                            a.name.toLowerCase().endsWith(".appimage")
                          );
                          if (asset) {
                            await invoke("download_and_install", {
                              url: asset.browser_download_url,
                              name: app.name,
                            });
                          } else {
                            await invoke("open_url", { url: `${app.github_url}/releases` });
                          }
                        } else if (downloadLink) {
                          await invoke("download_and_install", {
                            url: downloadLink.url,
                            name: app.name,
                          });
                        }
                        if (onRefreshLibrary) onRefreshLibrary();
                      } catch (e) {
                        setError(String(e));
                      } finally {
                        setDownloadingName(null);
                      }
                    }}
                    style={{
                      flex: 1,
                      background: "var(--accent-color)",
                      color: "#fff",
                      border: "none",
                      padding: "10px",
                      borderRadius: "6px",
                      cursor: isBusy ? "not-allowed" : "pointer",
                      display: "flex",
                      alignItems: "center",
                      justifyContent: "center",
                      fontWeight: "bold",
                      fontSize: "13px",
                      gap: "8px",
                      opacity: isBusy ? 0.7 : 1,
                    }}
                  >
                    <Download size={16} /> {isBusy ? "Installing..." : "Install"}
                  </button>
                )}

                {app.github_url && (
                  <button
                    onClick={() => invoke("open_url", { url: app.github_url })}
                    title="View GitHub Repository"
                    style={{
                      background: "var(--bg-input)",
                      color: "var(--text-primary)",
                      border: "1px solid var(--border-color)",
                      width: "40px",
                      borderRadius: "6px",
                      cursor: "pointer",
                      display: "flex",
                      alignItems: "center",
                      justifyContent: "center",
                    }}
                  >
                    <Github size={18} />
                  </button>
                )}
              </div>
            </div>
          );
        })}
      </div>

      {!loading && filteredApps.length === 0 && (
        <div
          style={{
            textAlign: "center",
            padding: "40px",
            color: "var(--text-muted)",
            background: "var(--bg-card)",
            borderRadius: "12px",
            border: "1px dashed var(--border-color)",
          }}
        >
          No applications found matching your search.
        </div>
      )}
    </div>
  );
};

export default Storefront;