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 @@ ...@@ -6,7 +6,7 @@
import { onMount, getContext } from 'svelte' import { onMount, getContext } from 'svelte'
import { get } from 'svelte/store' import { get } from 'svelte/store'
import { initialiseContext, state, signedIn} from './state.js' import { initialiseContext, state, signedIn, publicMessages} from './state.js'
// Initialise state. // Initialise state.
initialiseContext() initialiseContext()
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
// Make the public socket connection. // Make the public socket connection.
$publicSocket = new WebSocket(`wss://${location.hostname}/public`) $publicSocket = new WebSocket(`wss://${location.hostname}/public`)
$publicSocket.onmessage = message => { $publicSocket.onmessage = message => {
console.log(`Public message: ${message.data}`) $publicMessages = [...$publicMessages, message]
} }
// When signed in, make the private socket connection. // When signed in, make the private socket connection.
......
<script> <script>
import Section from './Section.svelte' import Section from './Section.svelte'
import { signedIn, privateMessages } from '../state' import { signedIn, publicMessages, privateMessages } from '../state'
const baseUrl = `https://${window.location.hostname}` const baseUrl = `https://${window.location.hostname}`
...@@ -69,6 +69,16 @@ ...@@ -69,6 +69,16 @@
<h3>Logs</h3> <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> <h4>Private messages:</h4>
<ul> <ul>
...@@ -79,5 +89,4 @@ ...@@ -79,5 +89,4 @@
{/each} {/each}
</ul> </ul>
</Section> </Section>
...@@ -5,12 +5,15 @@ import { writable } from 'svelte/store' ...@@ -5,12 +5,15 @@ import { writable } from 'svelte/store'
export const state = {} export const state = {}
export const signedIn = writable(false) export const signedIn = writable(false)
export const privateMessages = writable([]) export const privateMessages = writable([])
export const privateToken = writable(null) export const privateToken = writable(null)
export const privateSocket = writable(null) export const privateSocket = writable(null)
export const publicSocket = writable(null) export const publicSocket = writable(null)
export const publicMessages = writable([])
// Set initial application state, including the current section based on the hash. // Set initial application state, including the current section based on the hash.
export function initialiseContext () { 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