Skip to content

Commit

Permalink
show journal editor modal in full screen if screen is small
Browse files Browse the repository at this point in the history
  • Loading branch information
majorpeter committed Jan 7, 2024
1 parent 5ab4dd1 commit 144f52e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions frontend/src/pages/Dashboard/JournalEditorModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useState } from "react";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { RouteObject, useNavigate, useParams } from "react-router-dom";
import { Trans } from "react-i18next";

Expand Down Expand Up @@ -39,6 +39,18 @@ const JournalEditorModal: React.FC = () => {
const [userInput, setUserInput] = useState<string | undefined>();
const { data } = useApiQuery_journal_day(new Date(params.date!));

const [windowWidth, setWindowWidth] = useState<number>(window.innerWidth);
const onWindowResize = useCallback(() => {
setWindowWidth(window.innerWidth);
}, []);
useEffect(() => {
window.addEventListener("resize", onWindowResize);
return () => {
window.removeEventListener("resize", onWindowResize);
};
}, []);
const fullscreen = windowWidth < 600;

const {
mutate: mutateSave,
isPending: isSaving,
Expand Down Expand Up @@ -91,7 +103,7 @@ const JournalEditorModal: React.FC = () => {

return (
<Modal open onClose={handleClose}>
<ModalDialog>
<ModalDialog layout={fullscreen ? "fullscreen" : "center"}>
{!isSaving && <ModalClose />}
<DialogTitle>
<Trans i18nKey="journal">Journal</Trans>
Expand Down Expand Up @@ -129,7 +141,8 @@ const JournalEditorModal: React.FC = () => {
disabled={isSaving}
sx={{
width: { sm: 400 },
height: 200,
minHeight: 200,
height: "100%",
}}
></Textarea>

Expand Down

0 comments on commit 144f52e

Please sign in to comment.