forked from shellbear/shellbear.me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmarks.tsx
116 lines (105 loc) · 3.01 KB
/
bookmarks.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React from 'react';
import Head from 'next/head';
import { GetStaticPropsResult } from 'next';
import Image from 'next/image';
import TimeAgo from 'javascript-time-ago';
import { Title, Container, Text, Grid, Link, Card } from '@components';
import en from 'javascript-time-ago/locale/en';
TimeAgo.addDefaultLocale(en);
const timeAgo = new TimeAgo('en-US');
export interface Bookmark {
fields: Fields;
id: string;
created: number;
last_edited: number;
}
export interface Fields {
URL: string;
Name: string;
}
interface BookmarksProps {
bookmarks: Bookmark[];
}
const Bookmarks = ({ bookmarks }: BookmarksProps): JSX.Element => (
<Container marginBottom="5rem">
<Head>
<title>Bookmarks</title>
</Head>
<Container alignItems="center" mb="3rem">
<Title>Bookmarks</Title>
<Text textAlign="center">
Some interesting, useful and random stuff I want to read later.
</Text>
</Container>
<Grid
alignItems="baseline"
gridTemplateColumns={['1fr 1fr', 'repeat(3, 1fr)']}
gridGap={['1rem', '2rem']}
>
{bookmarks.map(({ id, fields, last_edited }) => (
<Link
target="_blank"
rel="noreferrer noopener"
key={id}
href={fields.URL}
>
<Card padding={0} margin={0} borderRadius="5px" display="block">
<Grid
gridTemplateColumns="1fr"
justifyItems={['center', 'flex-start']}
gridGap={['.2rem', '1rem']}
>
<Container width="100%" height="150px" position="relative">
<Image
layout="fill"
objectFit="cover"
src={`https://rdl.ink/render/${encodeURIComponent(
fields.URL,
)}`}
alt={fields.Name}
/>
</Container>
<Container
width="100%"
py=".5rem"
px={['.3rem', '1rem']}
gridGap={['.2rem', '.5rem']}
alignItems="flex-start"
>
<Title
as="h2"
fontSize={['0.8rem', '1.2rem']}
textAlign="left"
margin={0}
>
{fields.Name}
</Title>
<Text
margin={0}
fontWeight="initial"
fontSize={['.6rem', '.9rem']}
>
{timeAgo.format(new Date(last_edited))}
</Text>
</Container>
</Grid>
</Card>
</Link>
))}
</Grid>
</Container>
);
const BOOKMARKS_URL =
'https://potion-api.vercel.app/table?id=08ce7891a1824de8bac2ae8c77026383';
export const getServerSideProps = async (): Promise<
GetStaticPropsResult<BookmarksProps>
> => {
const result = await fetch(BOOKMARKS_URL);
const bookmarks = await result.json();
return {
props: {
bookmarks,
},
};
};
export default Bookmarks;