* start moving ui to redux tlk * remove unused reducer * changes for gdpr and site types * ui: migrating duck/roles to mobx * ui: drop unreferenced types * ui: drop unreferenced types * ui: move player slice reducer to mobx family * ui: move assignments to issueReportingStore.ts * remove issues store * some fixes after issues store * remove errors reducer, drop old components * finish removing errors reducer * start moving integrations state to mobx * change(ui): funnel duck cleanup * change(ui): custom fields * change(ui): customMetrics cleanup * change(ui): customMetrics cleanup * change(ui): duck/filters minor cleanup * change(ui): duck/filters cleanup * change(ui): duck/customMetrics cleanup and upgrades * fix integrations service, fix babel config to >.25 + not ie * refactoring integrations reducers etc WIP * finish removing integrations state * some fixes for integrated check * start of projects refactoring * move api and "few" files to new project store * new batch for site -> projects * fix setid context * move all critical components, drop site duck * remove all duck/site refs, remove old components * fixup for SessionTags.tsx, remove duck/sources (?) * move session store * init sessionstore outside of context * fix userfilter * replace simple actions for session store * sessions sotre * Rtm temp (#2597) * change(ui): duck/search wip * change(ui): duck/search wip * change(ui): duck/search wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): search states * change(ui): search states * change(ui): search states * change(ui): fix savedSearch store * change(ui): fix savedSearch store * some fixes for session connector * change(ui): fix savedSearch store * change(ui): fix searchLive * change(ui): fix searchLive * fixes for session replay * change(ui): bookmark fetch * last components for sessions * add fetchautoplaylist * finish session reducer, remove deleted reducers * change(ui): fix the search fetch * change(ui): fix the search fetch * fix integrations call ctx * ensure ctx for sessionstore * fix(ui): checking for latest sessions path * start removing user reducer * removing user reducer pt2... * finish user store * remove rand log * fix crashes * tinkering workflow file for tracker test * making sure prefetched sessions work properly * fix conflict * fix router redirects during loading --------- Co-authored-by: Shekar Siri <sshekarsiri@gmail.com>
144 lines
4.6 KiB
TypeScript
144 lines
4.6 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
import { Modal, Loader } from 'UI';
|
|
import { createIOSPlayer } from 'Player';
|
|
import { makeAutoObservable } from 'mobx';
|
|
import withLocationHandlers from 'HOCs/withLocationHandlers';
|
|
import { useStore } from 'App/mstore';
|
|
import MobilePlayerHeader from 'Components/Session/Player/MobilePlayer/MobilePlayerHeader';
|
|
import ReadNote from '../Session_/Player/Controls/components/ReadNote';
|
|
import PlayerContent from './Player/MobilePlayer/PlayerContent';
|
|
import { IOSPlayerContext, defaultContextValue, MobilePlayerContext } from './playerContext';
|
|
import { observer } from 'mobx-react-lite';
|
|
import { Note } from 'App/services/NotesService';
|
|
import { useParams } from 'react-router-dom';
|
|
import { toast } from 'react-toastify';
|
|
import PlayerErrorBoundary from 'Components/Session/Player/PlayerErrorBoundary';
|
|
|
|
const TABS = {
|
|
EVENTS: 'User Events',
|
|
};
|
|
|
|
let playerInst: IOSPlayerContext['player'] | undefined;
|
|
|
|
function MobilePlayer(props: any) {
|
|
const { notesStore, sessionStore, uiPlayerStore, integrationsStore, userStore } = useStore();
|
|
const session = sessionStore.current;
|
|
const [activeTab, setActiveTab] = useState('');
|
|
const [noteItem, setNoteItem] = useState<Note | undefined>(undefined);
|
|
// @ts-ignore
|
|
const [contextValue, setContextValue] = useState<IOSPlayerContext>(defaultContextValue);
|
|
const params: { sessionId: string } = useParams();
|
|
const fullscreen = uiPlayerStore.fullscreen
|
|
const toggleFullscreen = uiPlayerStore.toggleFullscreen
|
|
const closeBottomBlock = uiPlayerStore.closeBottomBlock
|
|
|
|
useEffect(() => {
|
|
playerInst = undefined;
|
|
if (!session.sessionId || contextValue.player !== undefined) return;
|
|
void integrationsStore.issues.fetchIntegrations();
|
|
sessionStore.setUserTimezone(session.timezone);
|
|
const [IOSPlayerInst, PlayerStore] = createIOSPlayer(
|
|
session,
|
|
(state) => makeAutoObservable(state),
|
|
toast
|
|
);
|
|
setContextValue({ player: IOSPlayerInst, store: PlayerStore });
|
|
playerInst = IOSPlayerInst;
|
|
|
|
notesStore.fetchSessionNotes(session.sessionId).then((r) => {
|
|
const note = props.query.get('note');
|
|
if (note) {
|
|
setNoteItem(notesStore.getNoteById(parseInt(note, 10), r));
|
|
IOSPlayerInst.pause();
|
|
}
|
|
});
|
|
}, [session.sessionId]);
|
|
|
|
const { messagesProcessed } = contextValue.store?.get() || {};
|
|
|
|
React.useEffect(() => {
|
|
if ((messagesProcessed && session.events.length > 0) || session.errors.length > 0) {
|
|
contextValue.player?.updateLists?.(session);
|
|
}
|
|
}, [session.events, session.errors, contextValue.player, messagesProcessed]);
|
|
|
|
React.useEffect(() => {
|
|
if (noteItem !== undefined) {
|
|
contextValue.player.pause();
|
|
}
|
|
|
|
if (activeTab === '' && !noteItem !== undefined && messagesProcessed && contextValue.player) {
|
|
const jumpToTime = props.query.get('jumpto');
|
|
|
|
if (jumpToTime) {
|
|
contextValue.player.jump(parseInt(jumpToTime));
|
|
}
|
|
|
|
contextValue.player.play();
|
|
}
|
|
}, [activeTab, noteItem, messagesProcessed]);
|
|
|
|
useEffect(
|
|
() => () => {
|
|
console.debug('cleaning up player after', params.sessionId);
|
|
toggleFullscreen(false);
|
|
closeBottomBlock();
|
|
playerInst?.clean();
|
|
// @ts-ignore
|
|
setContextValue(defaultContextValue);
|
|
},
|
|
[params.sessionId]
|
|
);
|
|
|
|
const onNoteClose = () => {
|
|
setNoteItem(undefined);
|
|
contextValue.player.play();
|
|
};
|
|
|
|
if (!session.sessionId)
|
|
return (
|
|
<Loader
|
|
size={75}
|
|
style={{
|
|
position: 'fixed',
|
|
top: '50%',
|
|
left: '50%',
|
|
transform: 'translateX(-50%)',
|
|
height: 75,
|
|
}}
|
|
/>
|
|
);
|
|
|
|
return (
|
|
<MobilePlayerContext.Provider value={contextValue}>
|
|
<MobilePlayerHeader
|
|
// @ts-ignore TODO?
|
|
activeTab={activeTab}
|
|
setActiveTab={setActiveTab}
|
|
tabs={TABS}
|
|
fullscreen={fullscreen}
|
|
/>
|
|
<PlayerErrorBoundary>
|
|
{contextValue.player ? (
|
|
<PlayerContent
|
|
activeTab={activeTab}
|
|
fullscreen={fullscreen}
|
|
setActiveTab={setActiveTab}
|
|
session={session}
|
|
/>
|
|
) : (
|
|
<Loader
|
|
style={{ position: 'fixed', top: '0%', left: '50%', transform: 'translateX(-50%)' }}
|
|
/>
|
|
)}
|
|
<Modal open={noteItem !== undefined} onClose={onNoteClose}>
|
|
{noteItem !== undefined ? (
|
|
<ReadNote note={noteItem} onClose={onNoteClose} notFound={!noteItem} />
|
|
) : null}
|
|
</Modal>
|
|
</PlayerErrorBoundary>
|
|
</MobilePlayerContext.Provider>
|
|
);
|
|
}
|
|
|
|
export default withLocationHandlers()(observer(MobilePlayer));
|