Commit 00b95503 authored by Aral Balkan's avatar Aral Balkan
Browse files

Improve transition to private section

parent 77715738
......@@ -7,15 +7,21 @@
const { privatePath } = getContext(state)
async function onShow() {
// NOTE: All this socket-related code should be taken out of the view.
let socketConnectionInitialised = false
let messages = []
function onShow() {
if (socketConnectionInitialised) return ''
console.log('Attempting to connect using private token', get(privatePath))
// Create a web socket connection.
const privateSocket = new WebSocket(`wss://${location.hostname}/private/${get(privatePath)}`)
privateSocket.onmessage = message => {
console.log('Got message', message)
messages = [...messages, message]
}
socketConnectionInitialised = true
return ''
}
</script>
......@@ -23,4 +29,9 @@
<Section path='/private' title='Private'>
{ onShow() }
<p>This is private.</p>
<ul>
{#each messages as message}
<li>{message.data}</li>
{/each}
</ul>
</Section>
......@@ -52,7 +52,7 @@
{#if value === null}
<p><strong>Sign in failed.</strong> Please try again.</p>
{:else}
{ signInSucceeded() }
{ signInSucceeded() ? '' : '' }
{/if}
{/if}
{:catch error}
......
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