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