Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-icons": "^4.3.1",
"react-router-dom": "6",
"react-scripts": "5.0.1",
"react-to-print": "^2.14.7",
"recoil": "^0.7.2",
"styled-components": "^5.3.3",
"typescript": "^4.6.3",
Expand Down
10 changes: 10 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@media print {
@page {
size: landscape;
}

body {
transform: scale(0.80);
display: block;
}
}
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { saveItem } from "./utils/localStorageUtil";
import { LANGUAGE_KEY } from "./constants";
import i18n from "./i18n";
import { getLanguageShortCode } from "./utils/languageUtil";
import "./App.css";

const lightTheme = createTheme({
palette: {
Expand Down
33 changes: 24 additions & 9 deletions src/components/root/Appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
appbarTitle,
isTimetableView,
menuOpen,
printTimetable,
subpage,
timetableInfoDialogOpen,
} from "../../states";
Expand All @@ -25,19 +26,22 @@ import { useNavigate } from "react-router-dom";
import InfoIconOutlined from "@mui/icons-material/InfoOutlined";
import SettingsIconOutlined from "@mui/icons-material/SettingsOutlined";
import SettingsMenuItems from "./SettingsMenuItems";
import PrintIconOutlined from "@mui/icons-material/PrintOutlined";

const Appbar = (): ReactElement => {
const [title] = useRecoilState(appbarTitle);
const [timetableView, setTimetableView] = useRecoilState(isTimetableView);
const setSelectedBranch = useSetRecoilState(actualTimetable);
const [drawerOpen, setDrawerOpen] = useRecoilState(menuOpen);
const setPrintTimetable = useSetRecoilState(printTimetable);
const setTimetableInfoOpen = useSetRecoilState(timetableInfoDialogOpen);
const [settingsAnchorElement, setSettingsAnchorElement] =
useState<HTMLElement | null>();
const settingsOpen = Boolean(settingsAnchorElement);
const isSubpage = useRecoilValue(subpage);
const navigate = useNavigate();

const handlePrintTimetable = () => setPrintTimetable(true);
const handleSettingsOpen = (event: React.MouseEvent<HTMLElement>) =>
setSettingsAnchorElement(event.currentTarget);
const handleSettingsClose = () => setSettingsAnchorElement(null);
Expand Down Expand Up @@ -106,15 +110,26 @@ const Appbar = (): ReactElement => {
<SettingsIconOutlined />
</IconButton>
{timetableView ? (
<IconButton
size="large"
edge="end"
color="inherit"
aria-label="menu"
onClick={handleExitButton}
>
<ExitToAppIcon />
</IconButton>
<>
<IconButton
size="large"
edge="end"
color="inherit"
aria-label="menu"
onClick={handlePrintTimetable}
>
<PrintIconOutlined />
</IconButton>
<IconButton
size="large"
edge="end"
color="inherit"
aria-label="menu"
onClick={handleExitButton}
>
<ExitToAppIcon />
</IconButton>
</>
) : null}
</Toolbar>
</AppBar>
Expand Down
5 changes: 5 additions & 0 deletions src/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ export const language = atom<string>({
key: "language",
default: getItem(LANGUAGE_KEY) ?? getLanguageShortCode(),
});

export const printTimetable = atom({
key: "printTimetable",
default: false,
});
19 changes: 18 additions & 1 deletion src/views/Timetable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, useEffect, useState } from "react";
import React, { ReactElement, useEffect, useRef, useState } from "react";
import TimetableGrid from "../components/timetable/TimetableGrid";
import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil";
import {
Expand All @@ -8,6 +8,7 @@ import {
errorMessage,
isTimetableView,
networkError,
printTimetable,
subpage,
timetableTitle,
} from "../states";
Expand All @@ -20,6 +21,7 @@ import { getSchoolDetails } from "../api/api";
import TimetableInfo from "../components/timetable/TimetableInfo";
import NetworkFailMessage from "../components/root/NetworkFailMessage";
import { changeTitle } from "../utils/titleUtil";
import { useReactToPrint } from "react-to-print";

const Timetable = (): ReactElement => {
const selectedBranch = useRecoilValue(actualTimetable);
Expand All @@ -32,6 +34,12 @@ const Timetable = (): ReactElement => {
const setErrorMessage = useSetRecoilState(errorMessage);
const [netError, setNetworkErrorMessage] = useRecoilState(networkError);
const setSubpage = useSetRecoilState(subpage);
const timetableRef = useRef();
const handlePrint = useReactToPrint({
content: () => timetableRef.current!,
removeAfterPrint: true,
});
const [printClicked, setPrintTimetable] = useRecoilState(printTimetable);
const { id } = useParams();

const onMount = () => {
Expand Down Expand Up @@ -78,6 +86,13 @@ const Timetable = (): ReactElement => {
document.title = changeTitle(`${schoolName} / ${selectedBranch!.name!}`);
}, [selectedBranch, netError]);

useEffect(() => {
if (!printClicked) return;

setPrintTimetable(false);
handlePrint();
}, [printClicked]);

onMount();

const NetworkErrorContainer = () => (
Expand All @@ -97,7 +112,9 @@ const Timetable = (): ReactElement => {
);

return (
// @ts-ignore
<Container
ref={timetableRef}
sx={{
minWidth: "90%",
}}
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9411,6 +9411,13 @@ react-scripts@5.0.1:
optionalDependencies:
fsevents "^2.3.2"

react-to-print@^2.14.7:
version "2.14.7"
resolved "https://registry.yarnpkg.com/react-to-print/-/react-to-print-2.14.7.tgz#d288de0e573e6e63e203a48d4bad7a1759d18688"
integrity sha512-lWVVAs9Co25uyE0toxcWeFsmaZObwUozXrJD9WMpDPclpBgk+WIzxlt3Q3omL/BCBG/cpf0XNvhayUWa+99YGw==
dependencies:
prop-types "^15.8.1"

react-transition-group@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.4.2.tgz#8b59a56f09ced7b55cbd53c36768b922890d5470"
Expand Down