OHIF-323: Cine Dialog (#1961)
* ohif-323: add cineplayer flow * ohif-323: improve toolbar flow of cine * ohif-323: improve cine styles * ohif-323: use toggle instead of set * ohif-323: add compatibility comment * ohif-323: move cine logic to command * ohif-323: cr update * ohif-323: remove typo and update svg title * ohif-323: remove log * ohif-323: update props and remove dead code Co-authored-by: Danny Brown <danny.ri.brown@gmail.com>
This commit is contained in:
1 parent
3e944780dc
commit
760e2a62ae
31 files changed
+575
-70
No files matched your search
@@ -0,0 +1,105 @@
|
||||
import React, {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useReducer,
|
||||
} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const DEFAULT_STATE = {
|
||||
isCineEnabled: false,
|
||||
cines: {
|
||||
/*
|
||||
* 1: { isPlaying: false, frameRate: 24 };
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
const DEFAULT_CINE = { isPlaying: false, frameRate: 24 };
|
||||
|
||||
export const CineContext = createContext(DEFAULT_STATE);
|
||||
|
||||
export default function CineProvider({ children, service }) {
|
||||
const reducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_CINE': {
|
||||
const { id, frameRate, isPlaying = undefined } = action.payload;
|
||||
const cines = state.cines;
|
||||
|
||||
if (!cines[id]) cines[id] = { id, ...DEFAULT_CINE };
|
||||
cines[id].frameRate = frameRate || cines[id].frameRate;
|
||||
cines[id].isPlaying = isPlaying !== undefined ? isPlaying : cines[id].isPlaying;
|
||||
|
||||
return { ...state, ...{ cines } };
|
||||
}
|
||||
case 'SET_IS_CINE_ENABLED': {
|
||||
return { ...state, ...{ isCineEnabled: action.payload } };
|
||||
}
|
||||
default:
|
||||
return action.payload;
|
||||
}
|
||||
};
|
||||
|
||||
const [state, dispatch] = useReducer(
|
||||
reducer,
|
||||
DEFAULT_STATE
|
||||
);
|
||||
|
||||
const getState = useCallback(() => state, [state]);
|
||||
|
||||
const setIsCineEnabled = useCallback(
|
||||
isCineEnabled => dispatch({ type: 'SET_IS_CINE_ENABLED', payload: isCineEnabled }),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const setCine = useCallback(
|
||||
({ id, frameRate, isPlaying }) =>
|
||||
dispatch({
|
||||
type: 'SET_CINE',
|
||||
payload: {
|
||||
id,
|
||||
frameRate,
|
||||
isPlaying,
|
||||
},
|
||||
}),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the implementation of a modal service that can be used by extensions.
|
||||
*
|
||||
* @returns void
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (service) {
|
||||
service.setServiceImplementation({ getState, setIsCineEnabled, setCine });
|
||||
}
|
||||
}, [
|
||||
getState,
|
||||
service,
|
||||
setCine,
|
||||
setIsCineEnabled,
|
||||
]);
|
||||
|
||||
const api = {
|
||||
getState,
|
||||
setCine,
|
||||
setIsCineEnabled,
|
||||
};
|
||||
|
||||
return (
|
||||
<CineContext.Provider value={[state, api]}>
|
||||
{children}
|
||||
</CineContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
CineProvider.propTypes = {
|
||||
children: PropTypes.any,
|
||||
service: PropTypes.shape({
|
||||
setServiceImplementation: PropTypes.func,
|
||||
}).isRequired,
|
||||
};
|
||||
|
||||
export const useCine = () => useContext(CineContext);
|
||||
@@ -11,9 +11,11 @@ const DEFAULT_STATE = {
|
||||
numRows: 1,
|
||||
numCols: 1,
|
||||
viewports: [
|
||||
// {
|
||||
// displaySetInstanceUID: string,
|
||||
// }
|
||||
/*
|
||||
* {
|
||||
* displaySetInstanceUID: string,
|
||||
* }
|
||||
*/
|
||||
],
|
||||
activeViewportIndex: 0,
|
||||
};
|
||||
@@ -59,7 +61,9 @@ export function ViewportGridProvider({ children, service }) {
|
||||
numCols: 1,
|
||||
numRows: 1,
|
||||
activeViewportIndex: 0,
|
||||
viewports: [{ displaySetInstanceUID: null }],
|
||||
viewports: [{
|
||||
displaySetInstanceUID: null,
|
||||
}],
|
||||
cachedLayout: null,
|
||||
};
|
||||
}
|
||||
@@ -84,13 +88,13 @@ export function ViewportGridProvider({ children, service }) {
|
||||
DEFAULT_STATE
|
||||
);
|
||||
|
||||
console.log('viewportGridState',viewportGridState)
|
||||
|
||||
const getState = useCallback(() => viewportGridState, [viewportGridState]);
|
||||
|
||||
const setActiveViewportIndex = useCallback(
|
||||
index => dispatch({ type: 'SET_ACTIVE_VIEWPORT_INDEX', payload: index }),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const setDisplaysetForViewport = useCallback(
|
||||
({ viewportIndex, displaySetInstanceUID }) =>
|
||||
dispatch({
|
||||
@@ -123,6 +127,7 @@ export function ViewportGridProvider({ children, service }) {
|
||||
}),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const setCachedLayout = useCallback(
|
||||
payload =>
|
||||
dispatch({
|
||||
|
||||
@@ -19,6 +19,12 @@ export {
|
||||
useImageViewer,
|
||||
} from './ImageViewerProvider';
|
||||
|
||||
export {
|
||||
CineContext,
|
||||
default as CineProvider,
|
||||
useCine,
|
||||
} from './CineProvider';
|
||||
|
||||
export {
|
||||
default as SnackbarProvider,
|
||||
useSnackbar,
|
||||
|
||||
Reference in new issue
Block a user