web/src/components/things/ServiceList.astro

396 lines · 9099 bytes

  1---
  2import Button from '@components/form/Button.astro';
  3import { parseMarkdown, formatLink } from '@utils/parse-markdown';
  4import type { Service } from 'src/types/Service';
  5import FontAwesome from '@components/form/FontAwesome.svelte';
  6import DeleteListing from '@components/things/DeleteListing.svelte';
  7import { slugify } from '@utils/fetch-data';
  8
  9import GitHubMetrics from '@components/things/ItemGitHubMetrics.astro';
 10import SaveListing from '@components/things/SaveListing.svelte';
 11
 12interface Props {
 13	services: Service[];
 14	subHeading?: boolean;
 15	buttonLink?: string;
 16	noGitHubMetrics?: boolean;
 17	sectionName: string;
 18	categoryName: string;
 19}
 20
 21const {
 22	services,
 23	subHeading,
 24	buttonLink,
 25	noGitHubMetrics,
 26	sectionName,
 27	categoryName,
 28} = Astro.props;
 29---
 30
 31<script>
 32	document.addEventListener('DOMContentLoaded', () => {
 33		const serviceIcons =
 34			document.querySelectorAll<HTMLImageElement>('.service-icon');
 35		const broke = '/broken-image.png';
 36
 37		serviceIcons.forEach(function (icon) {
 38			icon.onerror = function () {
 39				const imgElement = this as HTMLImageElement;
 40				const serviceUrl = imgElement.getAttribute('data-service-url');
 41				const newSrcAttribute = imgElement.src.includes('on.ho')
 42					? broke
 43					: `https://icon.horse/icon/${serviceUrl}`;
 44				imgElement.src =
 45					imgElement.src !== newSrcAttribute ? newSrcAttribute : broke;
 46				imgElement.onerror = null;
 47			};
 48		});
 49	});
 50</script>
 51
 52<section>
 53	{
 54		services && services.length > 0 ? (
 55			<ul>
 56				{services.map((service: Service) => (
 57					<li id={slugify(service.name)}>
 58						<DeleteListing
 59							client:load
 60							categoryName={categoryName}
 61							sectionName={sectionName}
 62							serviceName={service.name}
 63						/>
 64						<div class="save-listing">
 65							<SaveListing
 66								client:visible
 67								categoryName={categoryName}
 68								sectionName={sectionName}
 69								serviceName={service.name}
 70							/>
 71						</div>
 72						<div class="service-head">
 73							<img
 74								width="40"
 75								height="40"
 76								loading="lazy"
 77								decoding="async"
 78								class="service-icon"
 79								alt={`${service.name} Icon`}
 80								data-service-url={formatLink(service.url)}
 81								src={
 82									service.icon ||
 83									`https://icon.horse/icon/${formatLink(service.url)}`
 84								}
 85							/>
 86
 87							<a
 88								class="service-title"
 89								href={`/${slugify(categoryName)}/${slugify(sectionName)}/${slugify(service.name)}`}
 90							>
 91								{subHeading ? <h4>{service.name}</h4> : <h3>{service.name}</h3>}
 92							</a>
 93							{service.followWith && (
 94								<p class="follow-with">({service.followWith})</p>
 95							)}
 96							<a class="service-link" href={service.url}>
 97								{formatLink(service.url)}
 98							</a>
 99						</div>
100						<div class="service-body">
101							<p set:html={parseMarkdown(service.description)} />
102							<div class="service-stats">
103								<div class="left">
104									{service.securityAudited && (
105										<span
106											class="meta-item great"
107											title={`${service.name} has been security audited by an accredited auditor, with results published publicly`}
108										>
109											<FontAwesome iconName="securityAudited" /> Security
110											Audited
111										</span>
112									)}
113									{service.acceptsCrypto && (
114										<span
115											class="meta-item great"
116											title={`${service.name} accepts anonymous payment methods`}
117										>
118											<FontAwesome iconName="cryptoAccepted" /> Crypto Payments
119											Accepted
120										</span>
121									)}
122									{service.securityAudited === false && (
123										<span
124											class="meta-item warning"
125											title={`${service.name} has not been audited`}
126										>
127											<FontAwesome iconName="notSecurityAudited" /> No Security
128											Audit
129										</span>
130									)}
131									{service.openSource === false && (
132										<span class="warning">
133											<FontAwesome iconName="closedSource" />
134											Not Open Source
135										</span>
136									)}
137									{service.openSource ||
138									(service.github && service.openSource !== false) ? (
139										<span
140											class="meta-item great"
141											title={`${service.name} is open source`}
142										>
143											<FontAwesome iconName="openSource" /> Open Source
144										</span>
145									) : null}
146									{service.github && !noGitHubMetrics && (
147										<GitHubMetrics github={service.github} />
148									)}
149									{service.github && noGitHubMetrics && (
150										<span
151											class="meta-item"
152											title={`View ${service.name} on GitHub`}
153										>
154											<a
155												href={`https://github.com/${service.github}`}
156												target="_blank"
157											>
158												<FontAwesome iconName="github" /> {service.github}
159											</a>
160										</span>
161									)}
162								</div>
163								<div class="view-service">
164									<a
165										href={`/${slugify(categoryName)}/${slugify(sectionName)}/${slugify(service.name)}`}
166									>
167										View {service.name} Report
168									</a>
169								</div>
170							</div>
171						</div>
172					</li>
173				))}
174			</ul>
175		) : (
176			<p class="nothing-yet">
177				<>
178					<strong>⚠️ This section is still a work in progress ⚠️</strong>
179					<br />
180				</>
181				Check back soon, or help us complete it by submiting a pull request on
182				GitHub.
183				<br />
184				<span class="quick-submit">
185					Or submit an entry <a href="/submit">here</a>
186				</span>
187			</p>
188		)
189	}
190
191	{
192		buttonLink && (
193			<Button
194				title={`View all ${categoryName}`}
195				className="view-all"
196				text="View More..."
197				url={buttonLink}
198			/>
199		)
200	}
201</section>
202
203<style lang="scss">
204	section {
205		padding: 1rem 0;
206		position: relative;
207		&:not(:last-child) {
208			border-bottom: 2px solid var(--accent-3);
209		}
210	}
211
212	.nothing-yet {
213		font-size: 1.4rem;
214		opacity: 0.8;
215		font-style: italic;
216		text-align: center;
217		margin-bottom: 3rem;
218		.quick-submit {
219			margin-top: 1rem;
220			font-size: 0.8rem;
221			opacity: 0.8;
222		}
223	}
224
225	ul {
226		list-style: none;
227		padding: 0;
228		margin: 0 0 3rem 0;
229		li {
230			margin-bottom: 1rem;
231			position: relative;
232			.save-listing {
233				position: absolute;
234				right: 1rem;
235				top: 1rem;
236			}
237			.service-head {
238				display: flex;
239				align-items: center;
240				gap: 0.5rem;
241				flex-wrap: wrap;
242				.service-title {
243					text-decoration: none;
244					color: var(--foreground);
245					h3,
246					h4 {
247						margin: 0;
248						font-size: 1.6rem;
249					}
250
251					position: relative;
252					&:after {
253						background: none repeat scroll 0 0 transparent;
254						bottom: 0;
255						content: '';
256						display: block;
257						height: 3px;
258						left: 50%;
259						position: absolute;
260						background: var(--accent-3);
261						transition:
262							width 0.3s ease 0s,
263							left 0.3s ease 0s;
264						width: 0;
265					}
266					&:hover:after {
267						width: 100%;
268						left: 0;
269					}
270				}
271
272				.service-icon {
273					width: 2.5rem;
274					height: 2.5rem;
275					border-radius: var(--curve-sm);
276
277					font-size: 10px;
278					overflow: hidden;
279					color: var(--accent);
280				}
281				.follow-with {
282					opacity: 0.7;
283					font-style: italic;
284					margin: 0;
285				}
286				.service-link {
287					max-width: 300px;
288					text-overflow: ellipsis;
289					overflow: hidden;
290					white-space: nowrap;
291				}
292			}
293
294			.service-body {
295				margin: 0.5rem 0 2rem;
296				opacity: 0.8;
297				:global(p) {
298					margin: 0;
299					font-size: 1.2rem;
300					:global(a) {
301						color: var(--foregorund);
302					}
303				}
304				.service-stats {
305					.left {
306						display: flex;
307						gap: 1rem;
308						flex-wrap: wrap;
309						align-items: center;
310					}
311					display: flex;
312					gap: 1rem;
313					flex-wrap: wrap;
314					align-items: center;
315					justify-content: space-between;
316				}
317				.view-service {
318					transition: all 0.2s ease-in-out;
319					opacity: 0.95;
320					a {
321						padding: 0.25rem 0.6rem;
322						width: fit-content;
323						right: 1rem;
324						font-size: 0.9rem;
325						background: var(--accent-3);
326						color: var(--accent-fg);
327						text-decoration: none;
328						border-radius: var(--curve-md);
329					}
330					&:hover {
331						opacity: 1;
332						transform: scale(1.05);
333					}
334				}
335
336				.meta-item,
337				.warning {
338					display: flex;
339					align-items: center;
340					// justify-content: center;
341					gap: 0.25rem;
342					// opacity: 0.6;
343					font-size: 0.9rem;
344					padding: 0.5rem 0;
345					:global(svg) {
346						color: var(--foreground);
347						width: 1.2rem;
348						height: 1.2rem;
349					}
350					a {
351						text-decoration: none;
352						color: var(--foreground);
353						display: flex;
354						gap: 0.25rem;
355						&:hover {
356							color: var(--accent-3);
357							:global(svg) {
358								color: var(--accent-3);
359							}
360						}
361					}
362				}
363				.warning {
364					color: var(--danger);
365					:global(svg) {
366						color: var(--danger);
367					}
368				}
369				.great {
370					color: #0fb953; // var(--success);
371					:global(svg) {
372						color: #0fb953; // var(--success);
373					}
374				}
375			}
376		}
377	}
378
379	section :global(.view-all) {
380		width: fit-content;
381		position: absolute;
382		right: 1rem;
383		margin-top: -2.5rem;
384		background: var(--accent-3);
385	}
386
387	li:hover :global(.actions) {
388		opacity: 0.6;
389		:global(a):hover {
390			opacity: 1;
391		}
392	}
393	:global(.actions a):hover {
394		opacity: 1;
395	}
396</style>