Allow errored views to be reloaded

This commit is contained in:
Max Goodhart
2020-06-19 19:19:37 -07:00
parent 490b626a06
commit 570b07ed1e
4 changed files with 15 additions and 21 deletions

View File

@@ -23,7 +23,7 @@ Mousetrap.bind('ctrl+shift+i', () => {
function Overlay({ views, streams, customStreams }) { function Overlay({ views, streams, customStreams }) {
const activeViews = views const activeViews = views
.map(({ state, context }) => State.from(state, context)) .map(({ state, context }) => State.from(state, context))
.filter((s) => s.matches('displaying')) .filter((s) => s.matches('displaying') && !s.matches('displaying.error'))
return ( return (
<div> <div>
{activeViews.map((viewState) => { {activeViews.map((viewState) => {

View File

@@ -180,8 +180,7 @@ export default class StreamWindow extends EventEmitter {
reloadView(viewIdx) { reloadView(viewIdx) {
const view = this.views.find( const view = this.views.find(
(v) => (v) =>
v.state.matches('displaying') && v.state.context.pos && v.state.context.pos.spaces.includes(viewIdx),
v.state.context.pos.spaces.includes(viewIdx),
) )
if (view) { if (view) {
view.send('RELOAD') view.send('RELOAD')

View File

@@ -1,12 +1,5 @@
import { Machine, assign } from 'xstate' import { Machine, assign } from 'xstate'
const savePosIfSameURL = {
actions: assign({
pos: (context, event) => event.pos,
}),
cond: 'urlUnchanged',
}
const viewStateMachine = Machine( const viewStateMachine = Machine(
{ {
id: 'view', id: 'view',
@@ -31,7 +24,7 @@ const viewStateMachine = Machine(
invoke: { invoke: {
src: 'clearView', src: 'clearView',
onError: { onError: {
target: '#view.error', target: '#view.displaying.error',
}, },
}, },
}, },
@@ -43,7 +36,12 @@ const viewStateMachine = Machine(
url: (context, event) => event.url, url: (context, event) => event.url,
}), }),
on: { on: {
DISPLAY: savePosIfSameURL, DISPLAY: {
actions: assign({
pos: (context, event) => event.pos,
}),
cond: 'urlUnchanged',
},
RELOAD: '.loading', RELOAD: '.loading',
}, },
states: { states: {
@@ -57,7 +55,7 @@ const viewStateMachine = Machine(
target: 'video', target: 'video',
}, },
onError: { onError: {
target: '#view.error', target: '#view.displaying.error',
}, },
}, },
}, },
@@ -71,7 +69,7 @@ const viewStateMachine = Machine(
}), }),
}, },
onError: { onError: {
target: '#view.error', target: '#view.displaying.error',
}, },
}, },
}, },
@@ -103,12 +101,9 @@ const viewStateMachine = Machine(
}, },
}, },
}, },
}, error: {
}, entry: 'logError',
error: { },
entry: 'logError',
on: {
DISPLAY: savePosIfSameURL,
}, },
}, },
}, },

View File

@@ -164,7 +164,7 @@ function App({ wsEndpoint }) {
url={url} url={url}
onChangeSpace={handleSetView} onChangeSpace={handleSetView}
spaceValue={streamId} spaceValue={streamId}
isError={state.matches('error')} isError={state.matches('displaying.error')}
isDisplaying={state.matches('displaying')} isDisplaying={state.matches('displaying')}
isListening={isListening} isListening={isListening}
onSetListening={handleSetListening} onSetListening={handleSetListening}