web/src/components/things/DataActions.svelte
282 lines · 7201 bytes
1<script lang="ts">
2 import { onMount } from 'svelte';
3 import {
4 fetchSrcData,
5 makeRemovalRequest,
6 makeEditRequest,
7 } from '@utils/data-src-delete-n-edit';
8 import FontAwesome from '@components/form/FontAwesome.svelte';
9
10 import type { ChangelogPr } from '../../utils/fetch-changelog';
11
12 interface HistoryItem {
13 date: string;
14 type: 'added' | 'removed' | 'modified' | 'moved' | 'renamed';
15 fields?: string[];
16 from?: { category: string; section: string };
17 previousName?: string;
18 pr?: ChangelogPr | null;
19 }
20 interface Props {
21 categoryName: string;
22 sectionName: string;
23 serviceName: string;
24 history?: HistoryItem[];
25 }
26 const {
27 categoryName,
28 sectionName,
29 serviceName,
30 history = [],
31 }: Props = $props();
32
33 let lineNumbers: { start: number; end: number } | null = $state(null);
34 let yamlContent = $state('');
35
36 const getGitHubSrcFile = () => {
37 if (lineNumbers) {
38 const baseFile =
39 'https://github.com/lissy93/awesome-privacy/blob/main/awesome-privacy.yml';
40 return `${baseFile}#L${lineNumbers.start}-L${lineNumbers.end}`;
41 }
42 return '';
43 };
44
45 const getIframeSrc = () => {
46 const host = 'https://github-embed.as93.net';
47 const target = encodeURIComponent(getGitHubSrcFile());
48 const opts =
49 'style=felipec&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on';
50 return `${host}/iframe.html?target=${target}&${opts}`;
51 };
52
53 onMount(async () => {
54 const results = await fetchSrcData(categoryName, sectionName, serviceName);
55 lineNumbers = results.lineNumbers;
56 yamlContent = results.yamlContent;
57 });
58</script>
59
60{#if history.length > 0}
61 <h4>Change History</h4>
62 <ul class="history">
63 {#each history as h}
64 <li>
65 <span class="history-badge {h.type}">
66 {h.type === 'added'
67 ? 'Added'
68 : h.type === 'removed'
69 ? 'Removed'
70 : h.type === 'moved'
71 ? 'Moved'
72 : h.type === 'renamed'
73 ? 'Renamed'
74 : 'Amended'}
75 </span>
76 <time
77 >{new Date(h.date + 'T00:00:00Z').toLocaleDateString('en-US', {
78 month: 'short',
79 day: 'numeric',
80 year: 'numeric',
81 timeZone: 'UTC',
82 })}</time
83 >
84 {#if h.fields}<span class="history-fields">({h.fields.join(', ')})</span
85 >{/if}
86 {#if h.previousName}<span class="history-fields"
87 >previously: {h.previousName}</span
88 >{/if}
89 {#if h.from}<span class="history-fields"
90 >from {h.from.category} › {h.from.section}</span
91 >{/if}
92 {#if h.pr?.author}
93 <span class="history-author"
94 >by
95 <a
96 href={`https://github.com/${h.pr.author}`}
97 target="_blank"
98 rel="noreferrer">@{h.pr.author}</a
99 >
100 </span>
101 {/if}
102 {#if h.pr}
103 <a class="history-pr" href={h.pr.url} target="_blank" rel="noreferrer"
104 >#{h.pr.number}</a
105 >
106 {/if}
107 </li>
108 {/each}
109 </ul>
110{/if}
111
112{#if lineNumbers}
113 <h4>Edit {serviceName} Data</h4>
114 <p>
115 You can edit {serviceName}'s entry in
116 <a href={getGitHubSrcFile()}> this section </a>
117 of <code>awesome-privacy.yml</code> by submitting a PR to our GitHub repo.<br
118 />
119 Note that some of the information shown above has been aggregated from external
120 sources, a list of these can be found
121 <a href="/about#our-data">data documentation</a>.
122 </p>
123
124 <h4>Origin Data</h4>
125 <iframe
126 frameborder="0"
127 scrolling="no"
128 class="yaml-embed"
129 allow="clipboard-write"
130 title="awesome-privacy.yml"
131 src={getIframeSrc()}
132 ></iframe>
133
134 <h4>Modify Data</h4>
135 <div class="button-wrap">
136 <a
137 class="button-link"
138 target="_blank"
139 href={makeRemovalRequest(
140 categoryName,
141 sectionName,
142 serviceName,
143 yamlContent,
144 )}
145 >
146 <FontAwesome iconName="delete" /> Delete {serviceName}
147 </a>
148 <a
149 class="button-link"
150 target="_blank"
151 href={makeEditRequest(
152 categoryName,
153 sectionName,
154 serviceName,
155 yamlContent,
156 )}
157 >
158 <FontAwesome iconName="edit" /> Submit Edit to {serviceName}
159 </a>
160 <a class="button-link" href="/submit">
161 <FontAwesome iconName="add" /> Add alternative
162 </a>
163 </div>
164{/if}
165
166<style lang="scss">
167 @use '../../styles/mixins' as *;
168 h4 {
169 font-size: var(--text-lg);
170 margin-bottom: 0;
171 }
172 p {
173 margin: var(--space-xs) 0 var(--space-sm) 0;
174 }
175
176 .button-wrap {
177 display: flex;
178 gap: var(--space-md);
179 justify-content: center;
180 margin: var(--space-md) auto;
181 @media (max-width: 768px) {
182 flex-direction: column;
183 }
184 }
185 .button-link {
186 background: var(--accent-3);
187 border: var(--border-light);
188 box-shadow: var(--shadow-sm);
189 color: var(--accent-fg);
190 text-decoration: none;
191 border-radius: var(--curve-pill);
192 padding: var(--space-sm) var(--space-md);
193 font-weight: bold;
194 min-width: 15rem;
195 display: inline-block;
196 text-align: center;
197 font-family: var(--font-subtitle);
198 font-size: var(--text-md);
199 :global(svg) {
200 width: 1rem;
201 height: 1rem;
202 }
203 }
204
205 .history {
206 list-style: none;
207 padding: 0;
208 margin: var(--space-sm) 0 var(--space-md) 0;
209 li {
210 display: flex;
211 align-items: baseline;
212 gap: 0.4rem;
213 flex-wrap: wrap;
214 padding: 0.3rem 0;
215 font-size: 0.95rem;
216 border-bottom: 1px solid rgba(255, 255, 255, 0.05);
217 &:last-child {
218 border-bottom: none;
219 }
220 }
221 time {
222 opacity: var(--opacity-muted);
223 font-family: var(--font-subtitle);
224 font-size: var(--text-sm);
225 }
226 }
227 .history-badge {
228 @include changelog-badge;
229 font-size: var(--text-xs);
230 &.added {
231 background: color-mix(in srgb, var(--changelog-add) 33%, transparent);
232 color: var(--changelog-add);
233 }
234 &.removed {
235 background: color-mix(in srgb, var(--changelog-rem) 33%, transparent);
236 color: var(--changelog-rem);
237 }
238 &.modified,
239 &.moved,
240 &.renamed {
241 background: color-mix(in srgb, var(--changelog-mod) 33%, transparent);
242 color: var(--changelog-mod);
243 }
244 }
245 .history-fields {
246 font-size: var(--text-sm);
247 opacity: var(--opacity-dim);
248 font-style: italic;
249 }
250 .history-author {
251 font-size: var(--text-sm);
252 opacity: var(--opacity-soft);
253 a {
254 color: var(--foreground);
255 &:hover {
256 color: var(--accent);
257 }
258 }
259 }
260 .history-pr {
261 font-size: var(--text-xs);
262 padding: 0.05rem 0.3rem;
263 border-radius: var(--curve-sm);
264 background: var(--accent-3);
265 color: var(--accent-fg);
266 text-decoration: none;
267 font-family: var(--font-subtitle);
268 &:hover {
269 opacity: 0.85;
270 }
271 }
272
273 .yaml-embed {
274 width: 100%;
275 height: 370px;
276 border: 1px solid var(--accent-3);
277 border-radius: var(--curve-lg);
278 padding: 0;
279 margin: var(--space-md) auto;
280 box-shadow: 3px 3px 0 var(--accent-3);
281 }
282</style>