-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathindex.tsx
More file actions
236 lines (226 loc) · 7.12 KB
/
Copy pathindex.tsx
File metadata and controls
236 lines (226 loc) · 7.12 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
import * as React from 'react';
import Layout from '@theme/Layout';
import clsx from 'clsx';
import styles from './apps.module.scss';
import AppCard from './AppCard.tsx';
import { useState } from 'react';
import type { AppsPluginContent } from '../index.ts';
const SORTS = {
ALPHABETICAL: 'Alphabetical',
RECENT: 'Most Recent',
};
export default function AppsPage({ apps, categories }: AppsPluginContent) {
const [activeCategory, setActiveCategory] = useState(null);
const [activeSort, setActiveSort] = useState(SORTS.ALPHABETICAL);
const [activeQuery, setActiveQuery] = useState('');
const sortedApps = apps
.sort((a, b) => {
if (activeSort === SORTS.ALPHABETICAL) {
return a.name.localeCompare(b.name, 'en');
} else if (activeSort === SORTS.RECENT) {
return new Date(a.date) > new Date(b.date) ? -1 : 1;
}
})
.filter((app) => {
if (activeQuery && activeQuery !== '') {
return app.name.toLowerCase().includes(activeQuery);
} else {
return true;
}
});
const filters = Object.entries(categories);
const renderSort = (sort) => {
return (
<li
key={sort}
className={clsx(
'dropdown__link',
activeSort === sort && 'dropdown__link--active',
styles.sortDropdownItem,
)}
onClick={() => setActiveSort(sort)}
>
<span>{sort}</span>
</li>
);
};
const renderPillFilter = (filter) => {
const [name, entries] = filter;
return (
<li
key={name}
className={clsx(
'pills__item',
styles.pillFilter,
activeCategory && activeCategory[0] === name && 'pills__item--active',
)}
onClick={() => setActiveCategory(filter)}
>
<span>{name}</span>
<span className={clsx('badge badge--secondary', styles.filterBadge)}>
{entries.length}
</span>
</li>
);
};
const renderDropdownFilter = (filter) => {
const [name, entries] = filter;
return (
<li
key={name}
className={clsx(
'dropdown__link',
styles.dropdownFilterItem,
Array.isArray(activeCategory) &&
activeCategory[0] === name &&
'dropdown__link--active',
)}
onClick={() => setActiveCategory(filter)}
>
<span>{name}</span>
<span className={clsx('badge badge--secondary', styles.filterBadge)}>
{entries.length}
</span>
</li>
);
};
const currentFavs = sortedApps.filter(
(app) =>
app.isFavorite &&
(!Array.isArray(activeCategory) || app.category === activeCategory[0]),
);
return (
<Layout>
<main className="margin-vert--xl">
<h1 className={styles.title}>Showcase</h1>
<p className={styles.subtitle}>
Discover <strong>hundreds of production applications</strong> built
with Electron.
</p>
<div className={clsx('margin-bottom--md', styles.filtersContainer)}>
<div
className={clsx(
'container',
'margin-bottom--sm',
styles.sortAndSearchContainer,
)}
>
<div className="dropdown dropdown--hoverable">
<button className={clsx('button', styles.sortDropdownButton)}>
Sort: {activeSort}
</button>
<ul className={clsx('dropdown__menu', styles.sortDropdownMenu)}>
{Object.values(SORTS).map((s) => renderSort(s))}
</ul>
</div>
<div className="navbar__search">
<input
className="navbar__search-input"
placeholder="Search"
value={activeQuery}
onChange={(e) => {
setActiveQuery(e.target.value);
}}
/>
</div>
</div>
<ul className={clsx('pills', 'container', styles.pillFiltersList)}>
<li
className={clsx(
'pills__item',
styles.pillFilter,
activeCategory === null && 'pills__item--active',
)}
onClick={() => setActiveCategory(null)}
>
All
</li>
{filters
.sort((a, b) => b[1].length - a[1].length)
.map((cat) => renderPillFilter(cat))}
</ul>
<ul
className={clsx(
'dropdown dropdown--hoverable',
styles.dropdownFilter,
)}
>
<button className="button button--electron button--block">
{Array.isArray(activeCategory) ? activeCategory[0] : 'All'}
</button>
<ul className={clsx('dropdown__menu', styles.dropdownMenu)}>
<li
className={clsx(
'dropdown__link',
styles.dropdownFilterItem,
activeCategory === null && 'dropdown__link--active',
)}
onClick={() => setActiveCategory(null)}
>
All
</li>
{filters
.sort((a, b) => b[1].length - a[1].length)
.map((cat) => renderDropdownFilter(cat))}
</ul>
</ul>
</div>
{currentFavs.length > 0 && (
<div
className={clsx(
styles.favsContainer,
'container',
'shadow--tl',
'margin-bottom--xl',
)}
>
<h2 className={styles.sectionHeader}>Favorites ❤️</h2>
<div className={clsx(styles.appCardContainer)}>
{currentFavs.map((app) => {
return (
<AppCard
key={app.slug}
name={app.name}
description={app.description}
category={app.category}
logo={`https://raw.githubusercontent.com/electron/apps/main/apps/${app.slug}/${app.slug}-icon-128.png`}
isFavorite={true}
website={app.website}
repository={app.repository}
/>
);
})}
</div>
</div>
)}
<div
className={clsx(
styles.appCardContainer,
styles.allContainer,
'container',
'margin-bottom--xl',
)}
>
{sortedApps
.filter(
(app) => !activeCategory || app.category === activeCategory[0],
)
.map((app) => {
return (
<AppCard
key={app.slug}
name={app.name}
description={app.description}
category={app.category}
logo={`https://raw.githubusercontent.com/electron/apps/main/apps/${app.slug}/${app.slug}-icon-128.png`}
isFavorite={app.isFavorite}
website={app.website}
repository={app.repository}
/>
);
})}
</div>
</main>
</Layout>
);
}