web/src/components/things/PrivacyPolicyDetails.astro

187 lines · 4343 bytes

  1---
  2import type { PrivacyPolicyResponse } from '@utils/fetch-privacy-policy';
  3
  4import { formatDate, timeAgo } from '@utils/dates-n-stuff';
  5import FontAwesome from "@components/form/FontAwesome.svelte"
  6
  7
  8interface Props {
  9  privacyData: PrivacyPolicyResponse;
 10}
 11
 12const { privacyData } = Astro.props;
 13
 14const priv = privacyData.parameters;
 15
 16const getIconName = (clasification: string) => {
 17  if (clasification === 'good') return 'faceGood';
 18  if (clasification === 'neutral') return 'faceMeh';
 19  if (clasification === 'bad') return 'faceBad';
 20  return '';
 21}
 22
 23// If two or more objects in privacyPolicy.points have the same title, remove the duplicates
 24const removeDuplicates = () => {
 25  const seen = new Set();
 26  return priv.points = priv.points.filter((point) => {
 27    if (seen.has(point.title)) {
 28      return false;
 29    }
 30    seen.add(point.title);
 31    return true;
 32  });
 33}
 34
 35---
 36
 37{priv && (
 38<div class="privacy-policy-wrapper">
 39  
 40  {(priv.points && priv.points.length) > 0 && (
 41    <div class="left">
 42      <h4>Privacy Policy Summary</h4>
 43      <ul class="no-point">
 44        {removeDuplicates().map((point) => (
 45          <li class={`clasification ${point.case.classification}`}>
 46            <FontAwesome iconName={getIconName(point.case.classification)} />
 47            {point.title}
 48          </li>
 49        ))}
 50      </ul>
 51    </div>
 52  )}
 53  
 54  <div class="right">
 55    { priv.rating && (
 56      <h4>Score</h4>
 57      <div class={`rating rating-${priv.rating}`}>
 58        <p>{priv.rating}</p>
 59      </div>
 60    )}
 61    {priv.documents && priv.documents.length > 0 && (
 62      <h4>Documents</h4>
 63      <ul>
 64        {priv.documents.map((document) => (
 65          <li class="list-item">
 66            <a href={document.url} target="_blank">{document.name}</a>
 67            <div class="date-block">
 68              Created {formatDate(document.created_at)},
 69              Last modified {timeAgo(document.updated_at)}
 70            </div>
 71          </li>
 72        ))}
 73      </ul>
 74    )}
 75    {priv.urls && priv.urls.length > 1 && (
 76      <h4>Domains Covered by Policy</h4>
 77      <ul>
 78        {priv.urls.map((url) => (
 79          <li>{url}</li>
 80        ))}
 81      </ul>
 82    )}
 83    {priv.points && priv.points.length > 0 && (
 84      <h4>About the Data</h4>
 85      <p class="about-tosdr">
 86        This data is kindly provided by <a href="https://tosdr.org/">tosdr.org</a>.
 87        Read full report at: <a href={`https://tosdr.org/en/service/${priv.id}`}>#{priv.id}</a>
 88      
 89        </p>
 90    )}
 91  </div>
 92</div>
 93)}
 94
 95<style lang="scss">
 96
 97.privacy-policy-wrapper {
 98  display: flex;
 99  flex-wrap: wrap;
100  justify-content: space-between;
101  gap: 1rem;
102  .left, .right {
103    width: calc(50% - 1rem);
104    @media screen and (max-width: 768px){
105      width: 100%;
106    }
107  }
108}
109
110h4 {
111    margin: 1rem 0 0 0;
112    font-size: 1.2rem;
113  }
114  p {
115    margin: 0;
116    display: flex;
117    align-items: center;
118    gap: 0.25rem;
119    :global(svg) {
120      width: 1rem;
121    }
122    img {
123      border-radius: var(--curve-sm);
124    }
125  }
126  li {
127    :global(svg) {
128      width: 1rem;
129      margin-right: 0.2rem;
130    }
131    &.clasification {
132      &.good :global(svg) { color: #35b969; }
133      &.neutral :global(svg) { color: #ecd40f; }
134      &.bad :global(svg) { color: #e3154f; }
135    }
136  }
137  ul {
138    padding-left: 1rem;
139    list-style: circle;
140    max-height: 700px;
141    overflow-y: auto;
142    overflow-x: hidden;
143    img {
144      border-radius: var(--curve-sm);
145    }
146    .list-item {
147      display: flex;
148      flex-direction: column;
149      margin-bottom: 0.5rem;
150      .date-block {
151        
152        font-size: 0.8rem;
153        opacity: 0.7;
154      }
155    }
156    &.no-point {
157      list-style: none;
158      padding-left: 0.25rem;
159    }
160  }
161
162  .rating {
163    font-size: 4rem;
164    width: fit-content;
165    padding: 0.5rem 1.5rem;
166    border-radius: var(--curve-lg);
167    border: 4px solid;
168    margin: 0 auto;
169    font-weight: bold;
170
171    &.rating-A { --rating-color: #35b969; }
172    &.rating-B { --rating-color: #6bb935; }
173    &.rating-C { --rating-color: #c7cc22; }
174    &.rating-D { --rating-color: #e1bb23; }
175    &.rating-E { --rating-color: #df8b1e; }
176    &.rating-F { --rating-color: #df541e; }
177    &.rating-G { --rating-color: #df1e1e; }
178    color: var(--rating-color);
179    border-color: var(--rating-color);
180  }
181
182  .about-tosdr {
183    display: inline;
184    font-size: 0.8rem;
185    opacity: 0.7;
186  }
187</style>