web/src/components/things/RedditDetailedInfo.astro

172 lines · 3500 bytes

  1---
  2
  3import type { RedditData } from '@utils/fetch-reddit-info';
  4import { timestampToDate, timeAgo } from '@utils/dates-n-stuff'; 
  5import FontAwesome from "@components/form/FontAwesome.svelte"
  6
  7
  8interface Props {
  9  redditData: RedditData;
 10};
 11
 12const { redditData } = Astro.props;
 13
 14---
 15
 16<div class="reddit-info-wrapper">
 17    <div class="left">
 18      <h3>Reddit</h3>
 19      <p class="website-title">
 20        <img src={redditData.info.icon} width="16" />
 21        {redditData.info.title || redditData.info.name}
 22      </p>
 23      <p class="website-description">{redditData.info.description}</p>
 24      {redditData.info.banner && (<img class="banner" width="300" src={redditData.info.banner} alt="Banner" />)}
 25      <ul class="list-table">
 26        {redditData.info.dateCreated && (
 27        <li>
 28          <span class="lbl">Created at</span>
 29          <span class="val">{timestampToDate(redditData.info.dateCreated * 1000)}</span>
 30        </li>
 31        )}
 32        <li>
 33          <span class="lbl">Members</span>
 34          <span class="val">{redditData.info.subscribers}</span>
 35        </li>
 36        <li>
 37          <span class="lbl">Join</span>
 38          <span class="val"><a href={`https://reddit.com/${redditData.info.name}`}>{redditData.info.name}</a></span>
 39        </li>
 40      </ul>
 41    </div>
 42    <div class="right">
 43    <h4>Posts</h4>
 44    <ul class="posts">
 45      {redditData.posts.map((post) => (
 46        <li title={post.body}>
 47          ○ <a href={post.url} target="_blank">{post.title}</a>
 48          <span class="votes">(▲ {post.upVotes} ▼ {post.downVotes})</span>
 49        </li>
 50      ))}
 51    </ul>
 52  </div>
 53</div>
 54
 55
 56<style lang="scss">
 57.reddit-info-wrapper {
 58  display: flex;
 59  flex-wrap: wrap;
 60  justify-content: space-between;
 61  gap: 1rem;
 62  .left, .right {
 63    width: calc(50% - 1rem);
 64    @media screen and (max-width: 768px){
 65      width: 100%;
 66    }
 67  }
 68}
 69
 70.banner {
 71  margin: 0.5rem auto;
 72  border-radius: var(--curve-md);
 73  width: 100%;
 74}
 75
 76h3 {
 77  margin: 0 0 1rem 0;
 78  font-size: 1.6rem;
 79}
 80
 81h4 {
 82  margin: 1rem 0 0 0;
 83  font-size: 1.2rem;
 84}
 85p {
 86  margin: 0;
 87  display: flex;
 88  align-items: center;
 89  gap: 0.25rem;
 90  :global(svg) {
 91    width: 1rem;
 92  }
 93  img {
 94    border-radius: var(--curve-sm);
 95  }
 96}
 97
 98ul {
 99  padding-left: 0;
100  list-style: none;
101  max-height: 300px;
102  overflow-y: auto;
103  overflow-x: hidden;
104  img {
105    border-radius: var(--curve-sm);
106  }
107  .list-item {
108    display: flex;
109    flex-direction: column;
110    margin-bottom: 0.5rem;
111  }
112  &.list-table {
113    font-size: 0.9rem;
114    padding-left: 0;
115    li {
116      display: flex;
117      justify-content: space-between;
118      padding: 0.1rem 0;
119      .lbl {
120        font-weight: 400;
121      }
122      &:not(:last-child) {
123        border-bottom: 1px solid #5f53f440;
124      }
125    }
126  }
127}
128
129.posts {
130  list-style: circle;
131  padding-left: 1rem;
132  font-size: 0.9rem;
133  li {
134    display: -webkit-box;
135    -webkit-line-clamp: 1;
136    -webkit-box-orient: vertical;  
137    overflow: hidden;
138    a {
139      max-width: 80%;
140    }
141    .votes {
142      font-size: 0.8rem;
143      opacity: 0.5;
144    }
145  }
146}
147
148.website-title, .website-description {
149  font-size: 0.9rem;
150  opacity: 0.8;
151  display: -webkit-box;
152  -webkit-line-clamp: 1;
153  -webkit-box-orient: vertical;  
154  overflow: hidden;
155  border-left: 2px solid var(--accent-3);
156  padding-left: 0.5rem;
157}
158.website-title {
159  font-weight: 500;
160}
161.website-description {
162  font-style: italic;
163  -webkit-line-clamp: 3;
164}
165.explainer {
166  font-size: 0.8rem;
167  opacity: 0.8;
168  font-style: italic;
169}
170
171
172</style>