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 }) {
const activeViews = views
.map(({ state, context }) => State.from(state, context))
.filter((s) => s.matches('displaying'))
.filter((s) => s.matches('displaying') && !s.matches('displaying.error'))
return (
<div>
{activeViews.map((viewState) => {

View File

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

View File

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

View File

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