-
Notifications
You must be signed in to change notification settings - Fork 0
/
_History.svelte
94 lines (82 loc) · 1.95 KB
/
_History.svelte
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
<script>
import { log } from '../../_store.js';
import fuzzyTime from '$lib/utils/fuzzyTime.js';
import { onMount } from 'svelte';
let now = new Date();
let tableDiv;
onMount(() => {
setInterval(() => {
now = new Date();
}, 3000 + Math.random() * 3000);
tableDiv.scrollIntoView({ behavior: 'smooth', block: 'end' })
});
const alphabet = "abcdefghijklmnopqrstuvwxyz".split('');
function colorFromLetter(letter) {
const number = alphabet.indexOf(letter) + 1
if (number > alphabet.length * 3/4) {
return 'hsl(10, 100%, 71%)'
} else if (number > alphabet.length * 1/2) {
return 'hsl(53, 99%, 67%)'
} else if (number > alphabet.length * 1/4) {
return 'hsl(101, 79%, 63%)'
} else {
return 'hsl(208, 100%, 75%)'
}
}
</script>
<div class="table" bind:this={tableDiv}>
<div><h1>History</h1></div>
{#each $log as logItem, index (logItem.time)}
<div style="--accent: {colorFromLetter(logItem.message[0])}">
<div>{logItem.message}</div>
<div class="time">{fuzzyTime(now, logItem.time)}</div>
</div>
{/each}
</div>
<style lang="scss">
.table {
position: relative;
padding: 1rem 0 2rem 2rem;
display: flex;
flex-direction: column;
grid-gap: 3rem;
&::before {
content: '';
position: absolute;
top: 1rem;
left: 0.4rem;
width: 0.3rem;
height: calc(100% - 1rem);
background-color: hsla(0, 0%, 100%, 0.5);
border-radius: 0.3rem;
}
> div {
position: relative;
&:not(:first-child) {
& {
padding: 0.4rem 0.5rem;
background-color: hsla(0, 0%, 100%, 0.2);
border-radius: 0.5rem;
}
.time {
position: absolute;
font-size: 1rem;
bottom: -1.4rem;
left: 0;
width: 100%;
text-align: end;
}
&::before {
content: '';
position: absolute;
top: 0rem;
left: -2.5rem;
width: 2rem;
height: 2rem;
background-color: var(--accent);
border-radius: 100%;
}
}
}
}
</style>