Commit a0ec19002c
Unsigned
Layout: unified · split
web/src/components/things/DataActions.svelte added +120
| @@ -0,0 +1,120 @@ | ||
| 1 | <script lang="ts"> | |
| 2 | import { onMount } from "svelte"; | |
| 3 | import { fetchSrcData, makeRemovalRequest, makeEditRequest } from '@utils/data-src-delete-n-edit'; | |
| 4 | import FontAwesome from '@components/form/FontAwesome.svelte'; | |
| 5 | ||
| 6 | export let categoryName: string; | |
| 7 | export let sectionName: string; | |
| 8 | export let serviceName: string; | |
| 9 | ||
| 10 | let lineNumbers: { start: number, end: number } | null = null; | |
| 11 | let yamlContent = ''; | |
| 12 | ||
| 13 | const getGitHubSrcFile = () => { | |
| 14 | if (lineNumbers) { | |
| 15 | const baseFile = 'https://github.com/lissy93/awesome-privacy/blob/main/awesome-privacy.yml'; | |
| 16 | return `${baseFile}#L${lineNumbers.start}-L${lineNumbers.end}`; | |
| 17 | } | |
| 18 | return ''; | |
| 19 | }; | |
| 20 | ||
| 21 | const getIframeSrc = () => { | |
| 22 | const host = 'https://github-embed.as93.net'; | |
| 23 | const target = encodeURIComponent(getGitHubSrcFile()); | |
| 24 | const opts = 'style=color-brewer&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on'; | |
| 25 | return `${host}/iframe.html?target=${target}&${opts}`; | |
| 26 | }; | |
| 27 | ||
| 28 | ||
| 29 | onMount(async () => { | |
| 30 | const results = await fetchSrcData(categoryName, sectionName, serviceName); | |
| 31 | lineNumbers = results.lineNumbers | |
| 32 | yamlContent = results.yamlContent; | |
| 33 | }); | |
| 34 | ||
| 35 | </script> | |
| 36 | ||
| 37 | {#if lineNumbers} | |
| 38 | ||
| 39 | <h4>Edit {serviceName} Data</h4> | |
| 40 | <p> | |
| 41 | You can view or edit this {serviceName}'s entry in | |
| 42 | <a href={getGitHubSrcFile()}> | |
| 43 | this section | |
| 44 | </a> | |
| 45 | of <code>awesome-privacy.yml</code> in our GitHub repo. | |
| 46 | </p> | |
| 47 | ||
| 48 | <h4>Origin Data</h4> | |
| 49 | <iframe | |
| 50 | frameborder="0" | |
| 51 | scrolling="no" | |
| 52 | class="yaml-embed" | |
| 53 | allow="clipboard-write" | |
| 54 | title="awesome-privacy.yml" | |
| 55 | src={getIframeSrc()}></iframe> | |
| 56 | ||
| 57 | <h4>Edit/Delete Request</h4> | |
| 58 | <div class="button-wrap"> | |
| 59 | <a class="button-link" target="_blank" | |
| 60 | href={makeRemovalRequest(categoryName, sectionName, serviceName, yamlContent)}> | |
| 61 | <FontAwesome iconName="delete" /> Delete {serviceName} | |
| 62 | </a> | |
| 63 | <a class="button-link" target="_blank" | |
| 64 | href={makeEditRequest(categoryName, sectionName, serviceName, yamlContent)}> | |
| 65 | <FontAwesome iconName="edit" /> Submit Edit to {serviceName} | |
| 66 | </a> | |
| 67 | </div> | |
| 68 | ||
| 69 | {/if} | |
| 70 | ||
| 71 | ||
| 72 | <style lang="scss"> | |
| 73 | h4 { | |
| 74 | font-size: 1.4rem; | |
| 75 | margin-bottom: 0; | |
| 76 | } | |
| 77 | p { | |
| 78 | margin: 0.25rem 0 0.5rem 0; | |
| 79 | } | |
| 80 | ||
| 81 | .button-wrap { | |
| 82 | display: flex; | |
| 83 | gap: 1rem; | |
| 84 | justify-content: center; | |
| 85 | margin: 1rem auto; | |
| 86 | @media(max-width: 768px) { | |
| 87 | flex-direction: column; | |
| 88 | } | |
| 89 | } | |
| 90 | .button-link { | |
| 91 | background: var(--accent-3); | |
| 92 | border: 1px solid var(--foreground); | |
| 93 | box-shadow: 3px 3px 0 var(--foreground); | |
| 94 | color: var(--accent-fg); | |
| 95 | text-decoration: none; | |
| 96 | border-radius: 18px; | |
| 97 | padding: 0.5rem 1rem; | |
| 98 | font-weight: bold; | |
| 99 | min-width: 15rem; | |
| 100 | display: inline-block; | |
| 101 | text-align: center; | |
| 102 | font-family: "Lekton",sans-serif; | |
| 103 | font-size: 1.2rem; | |
| 104 | :global(svg) { | |
| 105 | width: 1rem; | |
| 106 | height: 1rem; | |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | .yaml-embed { | |
| 111 | width: 100%; | |
| 112 | height: 370px; | |
| 113 | border: 1px solid var(--accent-3); | |
| 114 | border-radius: var(--curve-lg); | |
| 115 | padding: 0; | |
| 116 | margin: 1rem auto; | |
| 117 | box-shadow: 3px 3px 0 var(--accent-3); | |
| 118 | } | |
| 119 | ||
| 120 | </style> | |
web/src/components/things/DeleteListing.svelte added +52
| @@ -0,0 +1,52 @@ | ||
| 1 | ||
| 2 | <script lang="ts"> | |
| 3 | import FontAwesome from '@components/form/FontAwesome.svelte'; | |
| 4 | import { fetchSrcData, makeRemovalRequest, makeEditRequest } from '@utils/data-src-delete-n-edit'; | |
| 5 | import { onMount } from 'svelte'; | |
| 6 | ||
| 7 | ||
| 8 | export let categoryName: string; | |
| 9 | export let sectionName: string; | |
| 10 | export let serviceName: string; | |
| 11 | ||
| 12 | let yamlContent = ''; | |
| 13 | ||
| 14 | onMount(async () => { | |
| 15 | const results = await fetchSrcData(categoryName, sectionName, serviceName); | |
| 16 | yamlContent = results.yamlContent; | |
| 17 | }); | |
| 18 | ||
| 19 | </script> | |
| 20 | ||
| 21 | <div class="actions"> | |
| 22 | <a title="Edit" target="_blank" | |
| 23 | href={makeEditRequest(categoryName, sectionName, serviceName, yamlContent)}> | |
| 24 | <FontAwesome iconName="edit" /> | |
| 25 | </a> | |
| 26 | <a title="Delete" target="_blank" | |
| 27 | href={makeRemovalRequest(categoryName, sectionName, serviceName, yamlContent)}> | |
| 28 | <FontAwesome iconName="delete" /> | |
| 29 | </a> | |
| 30 | </div> | |
| 31 | ||
| 32 | <style lang="scss"> | |
| 33 | .actions { | |
| 34 | position: absolute; | |
| 35 | right: 1rem; | |
| 36 | top: 1rem; | |
| 37 | width: 2.8rem; | |
| 38 | gap: 1rem; | |
| 39 | opacity: 0; | |
| 40 | display: flex; | |
| 41 | transition: all 0.2s ease-in-out; | |
| 42 | a { | |
| 43 | color: var(--foreground); | |
| 44 | width: 1rem; | |
| 45 | transition: all 0.2s ease-in-out; | |
| 46 | &:hover { | |
| 47 | color: var(--accent-3); | |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | } | |
| 52 | </style> | |
web/src/utils/data-src-delete-n-edit.ts added +44
| @@ -0,0 +1,44 @@ | ||
| 1 | import { slugify } from '@utils/fetch-data'; | |
| 2 | ||
| 3 | export const makeRemovalRequest = (categoryName: string, sectionName: string, serviceName: string, yaml?: string) => { | |
| 4 | const title = `[REMOVAL] ${serviceName}`; | |
| 5 | const under = `**${serviceName}** (source: [${categoryName} ➜ ${sectionName} ➜ ${serviceName}` | |
| 6 | + `](https://github.com/Lissy93/awesome-privacy/tree/main#${slugify(sectionName)}))`; | |
| 7 | const removalData = `&title=${encodeURIComponent(title)}&removal-data=` | |
| 8 | + `${encodeURIComponent(yaml || '')}&service-title=${encodeURIComponent(under)}`; | |
| 9 | const issueCreate = 'https://github.com/Lissy93/awesome-privacy/issues/new' | |
| 10 | const baseOptions = '?assignees=lissy93&labels=Suggested+Removal%2CAwaiting+' | |
| 11 | + 'Review&projects=&template=removal.yml' | |
| 12 | return `${issueCreate}${baseOptions}${removalData}`; | |
| 13 | }; | |
| 14 | ||
| 15 | export const makeEditRequest = (categoryName: string, sectionName: string, serviceName: string, yaml?: string) => { | |
| 16 | const title = `[AMENDMENT] ${serviceName}`; | |
| 17 | const under = `**${serviceName}** (source: [${categoryName} ➜ ${sectionName} ➜ ${serviceName}` | |
| 18 | + `](https://github.com/Lissy93/awesome-privacy/tree/main#${slugify(sectionName)}))`; | |
| 19 | const removalData = `&title=${encodeURIComponent(title)}&amendment-data=` | |
| 20 | + `${encodeURIComponent(yaml || '')}&service-title=${encodeURIComponent(under)}`; | |
| 21 | const issueCreate = 'https://github.com/Lissy93/awesome-privacy/issues/new' | |
| 22 | const baseOptions = '?assignees=lissy93&labels=Suggested+Removal%2CAwaiting+' | |
| 23 | + 'Review&projects=&template=amendment.yml' | |
| 24 | return `${issueCreate}${baseOptions}${removalData}`; | |
| 25 | }; | |
| 26 | ||
| 27 | export const fetchSrcData = async (categoryName: string, sectionName: string, serviceName: string) => { | |
| 28 | const lineNumberData = await fetch('/api/line-numbers.json') | |
| 29 | .then((res) => res.json()); | |
| 30 | ||
| 31 | if ( lineNumberData | |
| 32 | && lineNumberData[categoryName] | |
| 33 | && lineNumberData[categoryName][sectionName] | |
| 34 | && lineNumberData[categoryName][sectionName][serviceName] | |
| 35 | ) { | |
| 36 | return { | |
| 37 | lineNumbers: lineNumberData[categoryName][sectionName][serviceName].lineNumbers, | |
| 38 | yamlContent: lineNumberData[categoryName][sectionName][serviceName].yaml, | |
| 39 | }; | |
| 40 | } else { | |
| 41 | console.error('No line number data found for', categoryName, sectionName, serviceName); | |
| 42 | return { lineNumbers: [], yamlContent: '' }; | |
| 43 | } | |
| 44 | }; | |