Skip to content

Commit

Permalink
fullscreen indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
vsn4ik committed Jul 19, 2024
1 parent 4d0983b commit 9f66df9
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Shortcuts from "./pages/Shortcuts";
import Templates from "./pages/Templates";
import LandingPage from "./pages/LandingPage";
import SettingsContextProvider from "./context/SettingsContext";
import useSettings from "./hooks/useSettings";
import { useSettings } from "./hooks";
import NotFound from "./pages/NotFound";

export default function App() {
Expand Down
11 changes: 9 additions & 2 deletions src/components/EditorHeader/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ import {
useNotes,
useAreas,
useEnums,
useFullscreen,
} from "../../hooks";
import { enterFullscreen } from "../../utils/fullscreen";
import { enterFullscreen, exitFullscreen } from "../../utils/fullscreen";
import { dataURItoBlob } from "../../utils/utils";
import { IconAddArea, IconAddNote, IconAddTable } from "../../icons";
import LayoutDropdown from "./LayoutDropdown";
Expand Down Expand Up @@ -682,6 +683,7 @@ export default function ControlPanel({
const save = () => setSaveState(State.SAVING);
const open = () => setModal(MODAL.OPEN);
const saveDiagramAs = () => setModal(MODAL.SAVEAS);
const fullscreen = useFullscreen();

const menu = {
file: {
Expand Down Expand Up @@ -1204,7 +1206,12 @@ export default function ControlPanel({
shortcut: "Ctrl+Down/Wheel",
},
fullscreen: {
function: enterFullscreen,
state: fullscreen ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: fullscreen ? exitFullscreen : enterFullscreen,
},
},
settings: {
Expand Down
10 changes: 6 additions & 4 deletions src/components/EditorHeader/LayoutDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
IconRowsStroked,
} from "@douyinfe/semi-icons";
import { Dropdown } from "@douyinfe/semi-ui";
import { useLayout } from "../../hooks";
import { useFullscreen, useLayout } from "../../hooks";
import { enterFullscreen, exitFullscreen } from "../../utils/fullscreen";
import { useTranslation } from "react-i18next";

export default function LayoutDropdown() {
const fullscreen = useFullscreen();
const { layout, setLayout } = useLayout();
const { t } = useTranslation();

Expand Down Expand Up @@ -47,14 +48,15 @@ export default function LayoutDropdown() {
</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Item
icon={<div className="px-2" />}
icon={
fullscreen ? <IconCheckboxTick /> : <div className="px-2" />
}
onClick={() => {
if (layout.fullscreen) {
if (fullscreen) {
exitFullscreen();
} else {
enterFullscreen();
}
invertLayout("fullscreen");
}}
>
{t("fullscreen")}
Expand Down
4 changes: 1 addition & 3 deletions src/context/AreasContext.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createContext, useState } from "react";
import { Action, ObjectType, defaultBlue } from "../data/constants";
import useUndoRedo from "../hooks/useUndoRedo";
import useTransform from "../hooks/useTransform";
import useSelect from "../hooks/useSelect";
import { useUndoRedo, useTransform, useSelect } from "../hooks";
import { Toast } from "@douyinfe/semi-ui";
import { useTranslation } from "react-i18next";

Expand Down
4 changes: 1 addition & 3 deletions src/context/DiagramContext.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createContext, useState } from "react";
import { Action, DB, ObjectType, defaultBlue } from "../data/constants";
import useTransform from "../hooks/useTransform";
import useUndoRedo from "../hooks/useUndoRedo";
import useSelect from "../hooks/useSelect";
import { useTransform, useUndoRedo, useSelect } from "../hooks";
import { Toast } from "@douyinfe/semi-ui";
import { useTranslation } from "react-i18next";

Expand Down
1 change: 0 additions & 1 deletion src/context/LayoutContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default function LayoutContextProvider({ children }) {
sidebar: true,
issues: true,
toolbar: true,
fullscreen: false,
});

return (
Expand Down
4 changes: 1 addition & 3 deletions src/context/NotesContext.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createContext, useState } from "react";
import useTransform from "../hooks/useTransform";
import { Action, ObjectType, defaultNoteTheme } from "../data/constants";
import useUndoRedo from "../hooks/useUndoRedo";
import useSelect from "../hooks/useSelect";
import { useUndoRedo, useTransform, useSelect } from "../hooks";
import { Toast } from "@douyinfe/semi-ui";
import { useTranslation } from "react-i18next";

Expand Down
2 changes: 1 addition & 1 deletion src/context/TypesContext.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useState } from "react";
import { Action, ObjectType } from "../data/constants";
import useUndoRedo from "../hooks/useUndoRedo";
import { useUndoRedo } from "../hooks";
import { Toast } from "@douyinfe/semi-ui";
import { useTranslation } from "react-i18next";

Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as useAreas } from "./useAreas";
export { default as useCanvas } from "./useCanvas";
export { default as useFullscreen } from "./useFullscreen";
export { default as useLayout } from "./useLayout";
export { default as useNotes } from "./useNotes";
export { default as useSaveState } from "./useSaveState";
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/useFullscreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useState } from "react";
import { useEventListener } from "usehooks-ts";

export default function useFullscreen() {
const [value, setValue] = useState(() => {
return document.fullscreenElement === document.documentElement;
});

function handleFullscreenChange() {
setValue(document.fullscreenElement === document.documentElement);
}

useEventListener("fullscreenchange", handleFullscreenChange, document);

return value;
}

0 comments on commit 9f66df9

Please sign in to comment.