change(player): fix player unmount (#1112)

This commit is contained in:
Delirium 2023-04-05 18:31:42 +02:00 committed by GitHub
parent 8d34afebc4
commit 68fe2c722c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,15 +34,17 @@ function WebPlayer(props: any) {
const [visuallyAdjusted, setAdjusted] = useState(false);
// @ts-ignore
const [contextValue, setContextValue] = useState<IPlayerContext>(defaultContextValue);
let playerInst: IPlayerContext['player'];
useEffect(() => {
if (!session.sessionId) return;
if (!session.sessionId || contextValue.player !== undefined) return;
fetchList('issues');
const [WebPlayerInst, PlayerStore] = createWebPlayer(session, (state) =>
makeAutoObservable(state)
);
setContextValue({ player: WebPlayerInst, store: PlayerStore });
playerInst = WebPlayerInst;
notesStore.fetchSessionNotes(session.sessionId).then((r) => {
const note = props.query.get('note');
@ -61,12 +63,6 @@ function WebPlayer(props: any) {
if (freeze) {
WebPlayerInst.freeze()
}
return () => {
WebPlayerInst.clean();
// @ts-ignore
setContextValue(defaultContextValue);
}
}, [session.sessionId]);
React.useEffect(() => {
@ -97,6 +93,9 @@ function WebPlayer(props: any) {
() => () => {
toggleFullscreen(false);
closeBottomBlock();
playerInst?.clean();
// @ts-ignore
setContextValue(defaultContextValue);
},
[]
);