aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Feed.svelte
blob: c00fd1c70f16dfee3b07cca8cb566003794aba94 (plain) (blame)
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
<script>
	import { Avatar } from '$comp';
	import { browser } from '$app/environment';
	import VirtualScroll from 'svelte-virtual-scroll-list';
	import { punk } from '$lib/utils';
	export let events;

	let distance = (date) => {
		let m = 60;
		let h = 60 * m;
		let d = 24 * h;

		let diff = Math.round(Date.now() / 1000) - date;
		return diff > d
			? Math.round(diff / d) + 'd'
			: diff > h
			? Math.round(diff / h) + 'h'
			: diff > m
			? Math.round(diff / m) + 'm'
			: diff > 2
			? diff + 's'
			: 'now';
	};

	let w;
</script>

<svelte:window bind:innerWidth={w} />

{#if browser}
	<VirtualScroll data={events} key="id" let:data pageMode={true} estimateSize={200}>
		<div class="flex border-b py-4 text-sm lg:text-lg text-secondary" :key={data.id}>
			<a href={`/${data.user.anon ? data.user.pubkey : data.user.username}`}>
				<div class="mb-auto mr-2">
					<div class="md:hidden">
						<Avatar size={12} user={data.user} disabled={true} />
					</div>
					<div class="hidden md:block">
						<Avatar size={20} user={data.user} disabled={true} />
					</div>
				</div>
			</a>

			<div class="grow" style={`max-width: ${w - 100}px`}>
				<div class="w-full flex pb-1 text-black">
					<div>{data.user.username}</div>
					<div class="text-secondary">&nbsp;{distance(data.seen)}</div>
				</div>
				<div class="break-words">
					{data.content}
				</div>
			</div>
		</div>
	</VirtualScroll>
{/if}