-
Notifications
You must be signed in to change notification settings - Fork 1
%spin hint bar #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1 @@ | ||
| [%zuse 416] | ||
| [%zuse 415] | ||
| [%zuse 414] | ||
| [%zuse 413] | ||
| [%zuse 409] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import React, { useEffect, useState } from 'react'; | ||
| import { useDark } from './lib/useDark'; | ||
|
|
||
| export const SpinInfoBar = () => { | ||
| const [spinStack, setSpinStack] = useState<string[]>([]); | ||
| const dark = useDark(); | ||
|
|
||
| useEffect(() => { | ||
| console.log('spin: setting up...'); | ||
| let available = false; | ||
| const spin = new EventSource('/~_~/spin', { withCredentials: true }); | ||
|
|
||
| spin.onopen = () => { | ||
| console.log('spin: opened stream'); | ||
| available = true; | ||
| }; | ||
|
|
||
| spin.onmessage = (e) => { | ||
| console.log('spin message:', e.data); | ||
mopfel-winrux marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // The data is expected to be a path like /stack3/stack2/stack1/stack0 | ||
| // We need to parse it into an array of stack names | ||
| if (e.data && typeof e.data === 'string') { | ||
| // Remove leading slash if present and split by slash | ||
| const stackPath = e.data.startsWith('/') ? e.data.substring(1) : e.data; | ||
| const stackArray = stackPath.split('/').filter(Boolean); | ||
| setSpinStack(stackArray); | ||
mopfel-winrux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| }; | ||
|
|
||
| spin.onerror = (e) => { | ||
| console.error('spin: eventsource error:', e); | ||
| if (available) { | ||
| window.setTimeout(() => { | ||
| if (spin.readyState !== EventSource.CLOSED) { | ||
| return; | ||
| } | ||
| console.log('spin: reconnecting...'); | ||
| // We would call the setup function again here, but we don't want to | ||
| // create multiple event listeners in this effect | ||
| }, 10000); | ||
| } | ||
| }; | ||
mopfel-winrux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return () => { | ||
| spin.close(); | ||
| }; | ||
| }, []); | ||
|
|
||
| if (spinStack.length === 0) { | ||
| return null; | ||
| } | ||
|
Comment on lines
+37
to
+40
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes it to not render until we've heard something from the spin endpoint. Should be nearly instant usually, but you can imagine cases (problematic cases) where that takes a hot second or longer. This causes a rough "pop-in" effect, especially given that styling was updated so that the terminal window doesn't hit the bottom of the viewport until this element comes into existence. Should just render it unconditionally. |
||
|
|
||
| return ( | ||
| <div className="spin-info-bar" style={{ | ||
| backgroundColor: dark ? 'rgb(42, 42, 42)' : '#f0f0f0', | ||
| color: dark ? 'rgba(255, 255, 255, 0.9)' : 'black', | ||
| padding: '4px 10px', | ||
| fontSize: '12px', | ||
| fontFamily: 'monospace', | ||
| borderBottom: `1px solid ${dark ? 'rgba(255, 255, 255, 0.2)' : '#ccc'}`, | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| height: '24px', | ||
| }}> | ||
| <span style={{ marginRight: '5px', fontWeight: 'bold' }}>Spin Stack:</span> | ||
| {spinStack.map((stack, index) => ( | ||
| <React.Fragment key={index}> | ||
| {index > 0 && <span style={{ margin: '0 5px' }}>></span>} | ||
| <span style={{ | ||
| padding: '2px 6px', | ||
| backgroundColor: dark ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.05)', | ||
| borderRadius: '3px', | ||
| }}> | ||
| {stack} | ||
| </span> | ||
| </React.Fragment> | ||
| ))} | ||
| </div> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting that, with this and the
/~_~/slogendpoint, and of course the eyre channel for herm subscriptions, this page now opens three SSE connections to your ship's domain, which iirc browsers limit to some max amount per domain (not per tab/window).Of course, multi-tab urbiters are already hurting because of this, but this will hurt them even more.
Wonder if it's necessary, or if there even is some way we could demux/unify these connections somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just make it toggleable and off by default?