blob: 9c77a75d329f5cc304fe86a82e16dbcd02d7768d [file] [log] [blame]
Skyler Grey51e9e632023-06-03 10:20:11 +02001<script lang="ts">
2 import Button from '$components/ui/button/Button.svelte';
3 import Input from '$components/ui/input/Input.svelte';
4 import { onMount } from 'svelte';
5 import { flip } from 'svelte/animate';
6 import { fade } from 'svelte/transition';
7
8 export let form;
9
10 let messageInput: HTMLInputElement;
11 function focusMessageInput() {
12 messageInput.focus();
13 }
14
15 let systemMessage =
16 'Welcome to the void. Everything you put here is completely private. Messages will fade as they go up the page and disappear after a few minutes, or you can refresh the page to clear them too. Let out your frustrations and watch them slip away into the void...';
17 const resetMessage =
18 "Poof: it's gone; hopefully you feel a little better after letting your frustrations out. If there's something you still need to vent about feel free to continue. I'm still here to listen...";
19 let messages: string[] = [];
20 let currentlyTyped: string = '';
21
22 if (form?.pastMessages) {
23 messages = form?.pastMessages.toString().split('\n');
24 }
25
26 if (form?.message) {
27 messages.push(form?.message.toString());
28 }
29
30 if (form?.reset) {
31 systemMessage = resetMessage;
32 }
33
34 onMount(focusMessageInput);
35</script>
36
Skyler Greyf9eaa5f2023-06-03 12:45:39 +020037<svelte:head>
38 <title>The void</title>
39 <meta name="description" content="Have worries or frustrations? Let them out into the void" />
40 <meta property="og:title" content="The void" />
41 <meta property="og:description" content="Have worries or frustrations? Let them out into the void" />
42 <meta property="og:type" content="website" />
43 <meta name="keywords" content="void, vent, stress" />
44 <meta name="theme-color" content="#030711" />
45</svelte:head>
46
Skyler Grey51e9e632023-06-03 10:20:11 +020047<form
48 on:submit|preventDefault={() => {
49 messages.push(currentlyTyped);
50 messages = messages;
51 currentlyTyped = '';
52 focusMessageInput();
53 }}
54 method="post"
Skyler Grey57bcb4a2023-06-03 12:54:24 +020055 class="p-2 flex flex-col h-full gap-2 justify-end pt-0"
Skyler Grey51e9e632023-06-03 10:20:11 +020056>
57 <div class="flex p-2 pt-0 flex-col justify-end overflow-hidden pastMessages">
58 {#each (messages.length === 0 ? [systemMessage] : ['']).concat(messages) as message, index (`${index} ${message}`)}
59 <p class:message="{index !== 0}" transition:fade={{ duration: 100 }} animate:flip={{ duration: 100 }}>
60 {message}
61 </p>
62 {/each}
63 <input type="hidden" value={messages.join('\n')} name="pastMessages" />
64 </div>
65
66 <div class="flex w-full gap-2">
67 <Input
68 bind:element={messageInput}
69 bind:value={currentlyTyped}
70 name="message"
71 placeholder="Write down your worries, and let them slip into the void"
72 />
73 <Button type="submit">Send</Button>
74 <Button
75 name="reset"
76 value="reset"
77 on:click={() => {
78 currentlyTyped = '';
79 systemMessage = resetMessage;
80 messages = [systemMessage];
81 }}>Clean</Button
82 >
83 </div>
84</form>
85
86<style lang="postcss">
87 div.pastMessages::after {
88 content: '';
89 position: absolute;
90 top: 0;
91 left: 0;
92 z-index: 1;
93 width: 100%;
94 height: 100%;
95 background: linear-gradient(0deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 100%);
96 }
97
98 @keyframes message-fade-out {
99 0% {
100 opacity: 1;
101 }
102 100% {
103 opacity: 0;
104 }
105 }
106
107 p.message {
108 animation: message-fade-out 150s ease-in-out forwards;
109 }
110</style>