Commit 40b1444e authored by Aral Balkan's avatar Aral Balkan
Browse files

Keep global list of public messages; expose on About page

parent 8d942602
......@@ -6,7 +6,7 @@
import { onMount, getContext } from 'svelte'
import { get } from 'svelte/store'
import { initialiseContext, state, signedIn} from './state.js'
import { initialiseContext, state, signedIn, publicMessages} from './state.js'
// Initialise state.
initialiseContext()
......@@ -20,7 +20,7 @@
// Make the public socket connection.
$publicSocket = new WebSocket(`wss://${location.hostname}/public`)
$publicSocket.onmessage = message => {
console.log(`Public message: ${message.data}`)
$publicMessages = [...$publicMessages, message]
}
// When signed in, make the private socket connection.
......
<script>
import Section from './Section.svelte'
import { signedIn, privateMessages } from '../state'
import { signedIn, publicMessages, privateMessages } from '../state'
const baseUrl = `https://${window.location.hostname}`
......@@ -69,6 +69,16 @@
<h3>Logs</h3>
<h4>Public messages:</h4>
<ul>
{#each $publicMessages as message}
<li>{message.data}</li>
{:else}
<li>None yet.</li>
{/each}
</ul>
<h4>Private messages:</h4>
<ul>
......@@ -79,5 +89,4 @@
{/each}
</ul>
</Section>
......@@ -5,12 +5,15 @@ import { writable } from 'svelte/store'
export const state = {}
export const signedIn = writable(false)
export const privateMessages = writable([])
export const privateToken = writable(null)
export const privateSocket = writable(null)
export const publicSocket = writable(null)
export const publicMessages = writable([])
// Set initial application state, including the current section based on the hash.
export function initialiseContext () {
setContext(state, { signedIn, publicSocket, privateToken, privateSocket, privateMessages })
setContext(state, { signedIn, publicSocket, publicMessages, privateToken, privateSocket, privateMessages })
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment