-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.svelte
113 lines (96 loc) · 2.06 KB
/
index.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<script lang="ts">
import successkid from "images/successkid.jpg";
import { onMount } from "svelte";
import type { Socket } from "socket.io-client";
import Row from "../components/payload/Row.svelte";
import type Payload from "../components/payload/types/Payload";
let client: Socket;
let messages = [];
onMount(async () => {
console.log("start");
client = await import("socket.io-client").then((S) =>
S.connect({ path: "/p" })
);
console.log("Ready");
client.on("p", function (data: Payload) {
updateType(data.code);
messages = [
{
...data,
data: JSON.parse(data.data),
},
...messages,
];
});
});
let types = [];
function updateType(type: string) {
if (types.includes(type)) return;
types = [...types, type];
}
let activeTypes = [];
function toggleCode(type: string) {
if (activeTypes.includes(type)) {
activeTypes = activeTypes.filter((c) => c != type);
} else {
activeTypes = [...activeTypes, type];
}
}
</script>
<svelte:head>
<title>Sapper project template</title>
</svelte:head>
<h1>Great success!</h1>
<figure>
<img alt="Success Kid" src={successkid} />
<figcaption>Have fun with Sapper!</figcaption>
</figure>
<div class="filters">
{#each types as code}
<span
on:click={() => toggleCode(code)}
class:active={activeTypes.includes(code)}>{code}</span
>
{/each}
</div>
{#each messages.filter(({ code }) => activeTypes.includes(code)) as data}
<Row {data} />
{/each}
<style lang="scss">
div.filters {
span {
& .active {
font-weight: bold;
color: red;
}
}
}
h1,
figure,
p {
text-align: center;
margin: 0 auto;
}
h1 {
font-size: 2.8em;
text-transform: uppercase;
font-weight: 700;
margin: 0 0 0.5em 0;
}
figure {
margin: 0 0 1em 0;
}
img {
width: 100%;
max-width: 400px;
margin: 0 0 1em 0;
}
p {
margin: 1em auto;
}
@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
</style>