forked from theshubh77/launchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryCard.tsx
More file actions
160 lines (144 loc) · 4.21 KB
/
Copy pathDirectoryCard.tsx
File metadata and controls
160 lines (144 loc) · 4.21 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
"use client";
import React, { useState } from "react";
import {
ArrowUpRight,
RedditLogo,
XLogo,
FacebookLogo,
GithubLogo,
Globe
} from "@phosphor-icons/react";
import BorderGlow from "./BorderGlow";
interface DirectoryItem {
id: number;
name: string;
description: string;
submission_link: string;
}
interface DirectoryCardProps {
item: DirectoryItem;
theme: "light" | "dark";
}
export default function DirectoryCard({ item, theme }: DirectoryCardProps) {
const { name, description, submission_link } = item;
const [faviconError, setFaviconError] = useState(false);
// Helper to extract domain from URL
const getDomain = (url: string): string => {
try {
const parsed = new URL(url);
return parsed.hostname;
} catch {
return "";
}
};
const domain = getDomain(submission_link);
// Categorize directory based on name and link patterns
const getPlatform = (name: string, link: string) => {
const nameLower = name.toLowerCase();
const linkLower = link.toLowerCase();
if (nameLower.startsWith("r/") || /(?:^|[^a-z0-9-])reddit\.com(?:\/|\?|#|:|$)/i.test(linkLower)) {
return {
label: "Reddit",
class: "reddit",
icon: <RedditLogo size={16} weight="fill" />
};
}
if (nameLower.startsWith("x/") || /(?:^|[^a-z0-9-])(?:x|twitter)\.com(?:\/|\?|#|:|$)/i.test(linkLower)) {
return {
label: "X (Twitter)",
class: "x",
icon: <XLogo size={16} weight="bold" />
};
}
if (nameLower.startsWith("fb/") || /(?:^|[^a-z0-9-])(?:facebook|fb)\.com(?:\/|\?|#|:|$)/i.test(linkLower)) {
return {
label: "Facebook",
class: "facebook",
icon: <FacebookLogo size={16} weight="fill" />
};
}
if (nameLower.startsWith("gh/") || /(?:^|[^a-z0-9-])github\.com(?:\/|\?|#|:|$)/i.test(linkLower)) {
return {
label: "GitHub",
class: "github",
icon: <GithubLogo size={16} weight="fill" />
};
}
return {
label: "Web Directory",
class: "web",
icon: <Globe size={16} weight="bold" />
};
};
const platform = getPlatform(name, submission_link);
// Clean name: remove prefixes like "r/", "fb/", "gh/", "x/" for displaying
const cleanName = name.replace(/^(r\/|fb\/|gh\/|x\/)/i, "");
// Use Google Favicon Service
const faviconUrl = domain
? `https://www.google.com/s2/favicons?domain=${domain}&sz=64`
: null;
const cardContent = (
<>
<div className="card-header">
<div className="favicon-wrapper">
{faviconUrl && !faviconError ? (
<img
src={faviconUrl}
alt={`${cleanName} Favicon`}
className="favicon-img"
onError={() => setFaviconError(true)}
loading="lazy"
/>
) : (
<span className="favicon-fallback">
{cleanName.charAt(0).toUpperCase()}
</span>
)}
</div>
<span className={`platform-chip ${platform.class}`}>
{platform.icon}
{platform.label}
</span>
</div>
<div className="card-body">
<h3 className="card-title">{cleanName}</h3>
<p className="card-desc" title={description}>{description}</p>
</div>
<div className="card-footer">
<a
href={submission_link}
target="_blank"
rel="noopener noreferrer"
className="submit-btn"
>
<span className="submit-btn-text">Submit Product</span>
<ArrowUpRight size={18} />
</a>
</div>
</>
);
if (theme === "light") {
return (
<article className="card">
{cardContent}
</article>
);
}
return (
<BorderGlow
edgeSensitivity={30}
glowColor="260 80 80"
backgroundColor="var(--bg-secondary)"
borderRadius={16}
glowRadius={30}
glowIntensity={0.6}
coneSpread={30}
animated={false}
colors={['#8b5cf6', '#6366f1', '#a855f7']}
>
<article className="card" style={{ background: 'transparent', border: 'none', boxShadow: 'none', height: '100%', padding: '1.5rem', transform: 'none' }}>
{cardContent}
</article>
</BorderGlow>
);
}