web/src/components/things/DataActions.svelte

122 lines · 3133 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=felipec&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on';
 25    return `${host}/iframe.html?target=${target}&${opts}`;
 26  };
 27
 28  onMount(async () => {
 29    const results = await fetchSrcData(categoryName, sectionName, serviceName);
 30    lineNumbers = results.lineNumbers
 31    yamlContent = results.yamlContent;
 32  });
 33
 34</script>
 35
 36{#if lineNumbers}
 37
 38<h4>Edit {serviceName} Data</h4>
 39<p>
 40  You can view or edit this {serviceName}'s entry in
 41  <a href={getGitHubSrcFile()}>
 42    this section
 43  </a>
 44  of <code>awesome-privacy.yml</code> in our GitHub repo.
 45</p>
 46
 47<h4>Origin Data</h4>
 48<iframe
 49  frameborder="0"
 50  scrolling="no"
 51  class="yaml-embed"
 52  allow="clipboard-write"
 53  title="awesome-privacy.yml"
 54  src={getIframeSrc()}></iframe>
 55
 56<h4>Modify Data</h4>
 57<div class="button-wrap">
 58  <a class="button-link" target="_blank"
 59    href={makeRemovalRequest(categoryName, sectionName, serviceName, yamlContent)}>
 60    <FontAwesome iconName="delete" /> Delete {serviceName}
 61  </a>
 62  <a class="button-link" target="_blank"
 63    href={makeEditRequest(categoryName, sectionName, serviceName, yamlContent)}>
 64    <FontAwesome iconName="edit" /> Submit Edit to {serviceName}
 65  </a>
 66  <a class="button-link" href="/submit">
 67    <FontAwesome iconName="add" /> Add alternative
 68  </a>
 69</div>
 70
 71{/if}
 72
 73
 74<style lang="scss">
 75  h4 {
 76    font-size: 1.4rem;
 77    margin-bottom: 0;
 78  }
 79  p {
 80    margin: 0.25rem 0 0.5rem 0;
 81  }
 82
 83  .button-wrap {
 84    display: flex;
 85    gap: 1rem;
 86    justify-content: center;
 87    margin: 1rem auto;
 88    @media(max-width: 768px) {
 89      flex-direction: column;
 90    }
 91  }
 92  .button-link {
 93    background: var(--accent-3);
 94    border: 1px solid var(--box-outline);
 95    box-shadow: 3px 3px 0 var(--box-outline);
 96    color: var(--accent-fg);
 97    text-decoration: none;
 98    border-radius: 18px;
 99    padding: 0.5rem 1rem;
100    font-weight: bold;
101    min-width: 15rem;
102    display: inline-block;
103    text-align: center;
104    font-family: "Lekton",sans-serif;
105    font-size: 1.2rem;
106    :global(svg) {
107      width: 1rem;
108      height: 1rem;
109    }
110  }
111
112  .yaml-embed {
113    width: 100%;
114    height: 370px;
115    border: 1px solid var(--accent-3);
116    border-radius: var(--curve-lg);
117    padding: 0;
118    margin: 1rem auto;
119    box-shadow: 3px 3px 0 var(--accent-3);
120  }
121
122</style>