mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	feat(collection/presentation): add a button to toggle slide overview
This commit is contained in:
		| @@ -2031,7 +2031,8 @@ | |||||||
|   }, |   }, | ||||||
|   "presentation_view": { |   "presentation_view": { | ||||||
|     "edit-slide": "Edit this slide", |     "edit-slide": "Edit this slide", | ||||||
|     "start-presentation": "Start presentation" |     "start-presentation": "Start presentation", | ||||||
|  |     "slide-overview": "Toggle an overview of the slides" | ||||||
|   }, |   }, | ||||||
|   "command_palette": { |   "command_palette": { | ||||||
|     "tree-action-name": "Tree: {{name}}", |     "tree-action-name": "Tree: {{name}}", | ||||||
|   | |||||||
| @@ -52,6 +52,23 @@ export default function PresentationView({ note, noteIds }: ViewModeProps<{}>) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function ButtonOverlay({ containerRef, apiRef }: { containerRef: RefObject<HTMLDivElement>, apiRef: RefObject<Reveal.Api> }) { | function ButtonOverlay({ containerRef, apiRef }: { containerRef: RefObject<HTMLDivElement>, apiRef: RefObject<Reveal.Api> }) { | ||||||
|  |     const [ isOverviewActive, setIsOverviewActive ] = useState(false); | ||||||
|  |     useEffect(() => { | ||||||
|  |         const api = apiRef.current; | ||||||
|  |         if (!api) return; | ||||||
|  |         setIsOverviewActive(api.isOverview()); | ||||||
|  |         const onEnabled = () => setIsOverviewActive(true); | ||||||
|  |         const onDisabled = () => setIsOverviewActive(false); | ||||||
|  |         api.on("overviewshown", onEnabled); | ||||||
|  |         api.on("overviewhidden", onDisabled); | ||||||
|  |         return () => { | ||||||
|  |             api.off("overviewshown", onEnabled); | ||||||
|  |             api.off("overviewhidden", onDisabled); | ||||||
|  |         }; | ||||||
|  |     }, [ apiRef ]); | ||||||
|  |  | ||||||
|  |     console.log("Active ", isOverviewActive); | ||||||
|  |  | ||||||
|     return ( |     return ( | ||||||
|         <div className="presentation-button-bar"> |         <div className="presentation-button-bar"> | ||||||
|             <ActionButton |             <ActionButton | ||||||
| @@ -67,6 +84,15 @@ function ButtonOverlay({ containerRef, apiRef }: { containerRef: RefObject<HTMLD | |||||||
|                 }} |                 }} | ||||||
|             /> |             /> | ||||||
|  |  | ||||||
|  |             <ActionButton | ||||||
|  |                 icon="bx bx-grid-horizontal" | ||||||
|  |                 text={t("presentation_view.slide-overview")} | ||||||
|  |                 active={isOverviewActive} | ||||||
|  |                 onClick={() => { | ||||||
|  |                     apiRef.current?.toggleOverview(); | ||||||
|  |                 }} | ||||||
|  |             /> | ||||||
|  |  | ||||||
|             <ActionButton |             <ActionButton | ||||||
|                 icon="bx bx-fullscreen" |                 icon="bx bx-fullscreen" | ||||||
|                 text={t("presentation_view.start-presentation")} |                 text={t("presentation_view.start-presentation")} | ||||||
|   | |||||||
| @@ -5,16 +5,18 @@ import keyboard_actions from "../../services/keyboard_actions"; | |||||||
|  |  | ||||||
| export interface ActionButtonProps { | export interface ActionButtonProps { | ||||||
|     text: string; |     text: string; | ||||||
|     titlePosition?: "bottom" | "left"; |     titlePosition?: "top" | "right" | "bottom" | "left"; | ||||||
|     icon: string; |     icon: string; | ||||||
|     className?: string; |     className?: string; | ||||||
|     onClick?: (e: MouseEvent) => void; |     onClick?: (e: MouseEvent) => void; | ||||||
|     triggerCommand?: CommandNames; |     triggerCommand?: CommandNames; | ||||||
|     noIconActionClass?: boolean; |     noIconActionClass?: boolean; | ||||||
|     frame?: boolean; |     frame?: boolean; | ||||||
|  |     active?: boolean; | ||||||
|  |     disabled?: boolean; | ||||||
| } | } | ||||||
|  |  | ||||||
| export default function ActionButton({ text, icon, className, onClick, triggerCommand, titlePosition, noIconActionClass, frame }: ActionButtonProps) { | export default function ActionButton({ text, icon, className, onClick, triggerCommand, titlePosition, noIconActionClass, frame, active, disabled }: ActionButtonProps) { | ||||||
|     const buttonRef = useRef<HTMLButtonElement>(null); |     const buttonRef = useRef<HTMLButtonElement>(null); | ||||||
|     const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>(); |     const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>(); | ||||||
|  |  | ||||||
| @@ -32,8 +34,9 @@ export default function ActionButton({ text, icon, className, onClick, triggerCo | |||||||
|  |  | ||||||
|     return <button |     return <button | ||||||
|         ref={buttonRef} |         ref={buttonRef} | ||||||
|         class={`${className ?? ""} ${!noIconActionClass ? "icon-action" : "btn"} ${icon} ${frame ? "btn btn-primary" : ""}`} |         class={`${className ?? ""} ${!noIconActionClass ? "icon-action" : "btn"} ${icon} ${frame ? "btn btn-primary" : ""} ${disabled ? "disabled" : ""} ${active ? "active" : ""}`} | ||||||
|         onClick={onClick} |         onClick={onClick} | ||||||
|         data-trigger-command={triggerCommand} |         data-trigger-command={triggerCommand} | ||||||
|  |         disabled={disabled} | ||||||
|     />; |     />; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user