web/src/components/things/DataActions.svelte

123 lines · 3143 bytes

  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  <a class="button-link" href="/edit">
 68    <FontAwesome iconName="add" /> Add alternative
 69  </a>
 70</div>
 71
 72{/if}
 73
 74
 75<style lang="scss">
 76  h4 {
 77    font-size: 1.4rem;
 78    margin-bottom: 0;
 79  }
 80  p {
 81    margin: 0.25rem 0 0.5rem 0;
 82  }
 83
 84  .button-wrap {
 85    display: flex;
 86    gap: 1rem;
 87    justify-content: center;
 88    margin: 1rem auto;
 89    @media(max-width: 768px) {
 90      flex-direction: column;
 91    }
 92  }
 93  .button-link {
 94    background: var(--accent-3);
 95    border: 1px solid var(--foreground);
 96    box-shadow: 3px 3px 0 var(--foreground);
 97    color: var(--accent-fg);
 98    text-decoration: none;
 99    border-radius: 18px;
100    padding: 0.5rem 1rem;
101    font-weight: bold;
102    min-width: 15rem;
103    display: inline-block;
104    text-align: center;
105    font-family: "Lekton",sans-serif;
106    font-size: 1.2rem;
107    :global(svg) {
108      width: 1rem;
109      height: 1rem;
110    }
111  }
112
113  .yaml-embed {
114    width: 100%;
115    height: 370px;
116    border: 1px solid var(--accent-3);
117    border-radius: var(--curve-lg);
118    padding: 0;
119    margin: 1rem auto;
120    box-shadow: 3px 3px 0 var(--accent-3);
121  }
122
123</style>