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