1- import { messageHandler } from '@estruyf/vscode/dist/client/webview' ;
1+ import { messageHandler , Messenger } from '@estruyf/vscode/dist/client/webview' ;
22import * as React from 'react' ;
33import { COMMAND , WebViewMessages } from '../../constants' ;
44import { SlideControl } from './SlideControl' ;
55import { WhiteboardIcon } from './WhiteboardIcon' ;
66import { Icon } from 'vscrui' ;
7+ import { ProjectorIcon } from './ProjectorIcon' ;
8+ import { EventData } from '@estruyf/vscode' ;
79
810export interface ISlideControlsProps {
911 show : boolean ;
12+ path ?: string ;
1013}
1114
1215export const SlideControls : React . FunctionComponent < ISlideControlsProps > = ( {
13- show
16+ show,
17+ path
1418} : React . PropsWithChildren < ISlideControlsProps > ) => {
1519 const [ previousEnabled , setPreviousEnabled ] = React . useState ( false ) ;
20+ const [ isPresentationMode , setIsPresentationMode ] = React . useState ( false ) ;
21+
22+ const messageListener = ( message : MessageEvent < EventData < any > > ) => {
23+ const { command, payload } = message . data ;
24+ if ( ! command ) {
25+ return ;
26+ }
27+
28+ if ( command === WebViewMessages . toWebview . updateIsInPresentationMode ) {
29+ setIsPresentationMode ( payload ) ;
30+ }
31+ } ;
1632
1733 const previous = React . useCallback ( ( ) => {
1834 if ( previousEnabled ) {
@@ -40,6 +56,14 @@ export const SlideControls: React.FunctionComponent<ISlideControlsProps> = ({
4056 messageHandler . send ( WebViewMessages . toVscode . runCommand , "demo-time.focus" ) ;
4157 } , [ ] ) ;
4258
59+ const togglePresentationMode = React . useCallback ( ( ) => {
60+ messageHandler . send ( WebViewMessages . toVscode . runCommand , "demo-time.togglePresentationMode" ) ;
61+ } , [ ] ) ;
62+
63+ const openSlideSource = React . useCallback ( ( ) => {
64+ messageHandler . send ( WebViewMessages . toVscode . openFile , path ) ;
65+ } , [ path ] ) ;
66+
4367 React . useEffect ( ( ) => {
4468 if ( show ) {
4569 messageHandler . request < boolean > ( WebViewMessages . toVscode . getPreviousEnabled ) . then ( ( previous ) => {
@@ -48,6 +72,19 @@ export const SlideControls: React.FunctionComponent<ISlideControlsProps> = ({
4872 }
4973 } , [ show ] ) ;
5074
75+ React . useEffect ( ( ) => {
76+ messageHandler . request < boolean > ( WebViewMessages . toVscode . getPresentationStarted ) . then ( ( value ) => {
77+ console . log ( "value" , value ) ;
78+ setIsPresentationMode ( value ) ;
79+ } ) ;
80+
81+ Messenger . listen ( messageListener ) ;
82+
83+ return ( ) => {
84+ Messenger . unlisten ( messageListener ) ;
85+ } ;
86+ } , [ ] ) ;
87+
5188 return (
5289 < div
5390 className = { `absolute bottom-0 w-full transition-opacity duration-300 ${ show ? 'opacity-90' : 'opacity-0 pointer-events-none'
@@ -58,6 +95,7 @@ export const SlideControls: React.FunctionComponent<ISlideControlsProps> = ({
5895 style = { { boxShadow : '0 0 8px 0 var(--vscode-widget-shadow)' } }
5996 >
6097 < div className = 'flex items-center' >
98+ < SlideControl title = "Toggle presentation mode" className = { `${ isPresentationMode ? `bg-[var(--vscode-statusBarItem-errorBackground)] hover:-[var(--vscode-statusBarItem-errorHoverBackground)]` : '' } ` } icon = { < ProjectorIcon className = { `w-4 h-4 inline-flex justify-center items-center ${ isPresentationMode ? `text-[var(--vscode-statusBarItem-errorForeground)] hover:text-[var(--vscode-statusBarItem-errorHoverForeground)]` : `text-[var(--vscode-editorWidget-foreground)]` } ` } /> } action = { togglePresentationMode } />
6199 < SlideControl title = "Toggle fullscreen" iconName = "screen-full" action = { toggleFullscreen } />
62100 < SlideControl title = "Toggle presentation view" icon = { < WhiteboardIcon className = "w-4 h-4 text-[var(--vscode-editorWidget-foreground)] inline-flex justify-center items-center" /> } action = { togglePresentationView } />
63101 < SlideControl title = "Close sidebar" icon = { (
@@ -80,7 +118,13 @@ export const SlideControls: React.FunctionComponent<ISlideControlsProps> = ({
80118
81119 < SlideControl title = "Next" iconName = "arrow-right" action = { next } isSlideControl />
82120 </ div >
83- < div > </ div >
121+ < div className = "flex items-center justify-end gap-4" >
122+ {
123+ path && (
124+ < SlideControl title = "Open slide source" iconName = "preview" action = { openSlideSource } />
125+ )
126+ }
127+ </ div >
84128 </ div >
85129 </ div >
86130 ) ;
0 commit comments