add compact mode
This commit is contained in:
@@ -15,6 +15,7 @@ import { UploadButton } from "../Backup/UploadButton";
|
|||||||
import { DiscordButton } from "../Discord/DiscordButton";
|
import { DiscordButton } from "../Discord/DiscordButton";
|
||||||
import { GitHubButton } from "../Github/GitHubButton";
|
import { GitHubButton } from "../Github/GitHubButton";
|
||||||
import { CCPButton } from "../CCP/CCPButton";
|
import { CCPButton } from "../CCP/CCPButton";
|
||||||
|
import { CompactModeButton } from "../CompactModeButton/CompactModeButton";
|
||||||
|
|
||||||
function ResponsiveAppBar() {
|
function ResponsiveAppBar() {
|
||||||
const [anchorElNav, setAnchorElNav] = React.useState<null | HTMLElement>(
|
const [anchorElNav, setAnchorElNav] = React.useState<null | HTMLElement>(
|
||||||
@@ -120,13 +121,17 @@ function ResponsiveAppBar() {
|
|||||||
>
|
>
|
||||||
EVE PI
|
EVE PI
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box sx={{ flexGrow: 1, display: { xs: "none", md: "flex" } }}>
|
<Box
|
||||||
|
sx={{ flexGrow: 1, display: { xs: "none", md: "flex" } }}
|
||||||
|
style={{ display: "flex", alignItems: "center" }}
|
||||||
|
>
|
||||||
<LoginButton />
|
<LoginButton />
|
||||||
<DowloadButton />
|
<DowloadButton />
|
||||||
<UploadButton />
|
<UploadButton />
|
||||||
<DiscordButton />
|
<DiscordButton />
|
||||||
<GitHubButton />
|
<GitHubButton />
|
||||||
<CCPButton />
|
<CCPButton />
|
||||||
|
<CompactModeButton />
|
||||||
</Box>
|
</Box>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</Container>
|
</Container>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { CharacterContext, SessionContext } from "@/app/context/Context";
|
import { CharacterContext } from "@/app/context/Context";
|
||||||
import { Button, Tooltip } from "@mui/material";
|
import { Button, Tooltip } from "@mui/material";
|
||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
|
|
||||||
|
19
src/app/components/CompactModeButton/CompactModeButton.tsx
Normal file
19
src/app/components/CompactModeButton/CompactModeButton.tsx
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { SessionContext } from "@/app/context/Context";
|
||||||
|
import { ToggleButton, Tooltip } from "@mui/material";
|
||||||
|
import { useContext } from "react";
|
||||||
|
|
||||||
|
export const CompactModeButton = () => {
|
||||||
|
const { compactMode, toggleCompactMode } = useContext(SessionContext);
|
||||||
|
return (
|
||||||
|
<Tooltip title="Export your EVE PI list to transfer to another device or backup">
|
||||||
|
<ToggleButton
|
||||||
|
value="check"
|
||||||
|
selected={compactMode}
|
||||||
|
onChange={toggleCompactMode}
|
||||||
|
style={{ margin: "1rem 0" }}
|
||||||
|
>
|
||||||
|
Compact mode
|
||||||
|
</ToggleButton>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
@@ -1,4 +1,4 @@
|
|||||||
import { useContext } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
CssBaseline,
|
CssBaseline,
|
||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { AccountCard } from "./Account/AccountCard";
|
import { AccountCard } from "./Account/AccountCard";
|
||||||
import { AccessToken } from "@/types";
|
import { AccessToken } from "@/types";
|
||||||
import { CharacterContext } from "../context/Context";
|
import { CharacterContext, SessionContext } from "../context/Context";
|
||||||
import ResponsiveAppBar from "./AppBar/AppBar";
|
import ResponsiveAppBar from "./AppBar/AppBar";
|
||||||
|
|
||||||
interface Grouped {
|
interface Grouped {
|
||||||
@@ -23,6 +23,7 @@ const darkTheme = createTheme({
|
|||||||
|
|
||||||
export const MainGrid = ({ sessionReady }: { sessionReady: boolean }) => {
|
export const MainGrid = ({ sessionReady }: { sessionReady: boolean }) => {
|
||||||
const { characters } = useContext(CharacterContext);
|
const { characters } = useContext(CharacterContext);
|
||||||
|
const { compactMode } = useContext(SessionContext);
|
||||||
const groupByAccount = characters.reduce<Grouped>((group, character) => {
|
const groupByAccount = characters.reduce<Grouped>((group, character) => {
|
||||||
const { account } = character;
|
const { account } = character;
|
||||||
group[account ?? ""] = group[account ?? ""] ?? [];
|
group[account ?? ""] = group[account ?? ""] ?? [];
|
||||||
@@ -36,7 +37,11 @@ export const MainGrid = ({ sessionReady }: { sessionReady: boolean }) => {
|
|||||||
<Box sx={{ flexGrow: 1 }}>
|
<Box sx={{ flexGrow: 1 }}>
|
||||||
<ResponsiveAppBar />
|
<ResponsiveAppBar />
|
||||||
<Grid container spacing={1}>
|
<Grid container spacing={1}>
|
||||||
<Grid item xs={12}>
|
<Grid
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
style={{ display: compactMode ? "flex" : "block" }}
|
||||||
|
>
|
||||||
{Object.values(groupByAccount).map((g, id) => (
|
{Object.values(groupByAccount).map((g, id) => (
|
||||||
<AccountCard
|
<AccountCard
|
||||||
key={`account-${id}-${g[0].account}`}
|
key={`account-${id}-${g[0].account}`}
|
||||||
|
@@ -19,10 +19,14 @@ export const SessionContext = createContext<{
|
|||||||
setSessionReady: Dispatch<SetStateAction<boolean>>;
|
setSessionReady: Dispatch<SetStateAction<boolean>>;
|
||||||
EVE_SSO_CALLBACK_URL: string;
|
EVE_SSO_CALLBACK_URL: string;
|
||||||
EVE_SSO_CLIENT_ID: string;
|
EVE_SSO_CLIENT_ID: string;
|
||||||
|
compactMode: boolean;
|
||||||
|
toggleCompactMode: () => void;
|
||||||
}>({
|
}>({
|
||||||
sessionReady: false,
|
sessionReady: false,
|
||||||
refreshSession: () => {},
|
refreshSession: () => {},
|
||||||
setSessionReady: () => {},
|
setSessionReady: () => {},
|
||||||
EVE_SSO_CALLBACK_URL: "",
|
EVE_SSO_CALLBACK_URL: "",
|
||||||
EVE_SSO_CLIENT_ID: "",
|
EVE_SSO_CLIENT_ID: "",
|
||||||
|
compactMode: false,
|
||||||
|
toggleCompactMode: () => {},
|
||||||
});
|
});
|
||||||
|
@@ -14,6 +14,7 @@ const Home = () => {
|
|||||||
const [characters, setCharacters] = useState<AccessToken[]>([]);
|
const [characters, setCharacters] = useState<AccessToken[]>([]);
|
||||||
const [sessionReady, setSessionReady] = useState(false);
|
const [sessionReady, setSessionReady] = useState(false);
|
||||||
const [environment, setEnvironment] = useState<Env | undefined>(undefined);
|
const [environment, setEnvironment] = useState<Env | undefined>(undefined);
|
||||||
|
const [compactMode, setCompactMode] = useState(false);
|
||||||
|
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const code = searchParams && searchParams.get("code");
|
const code = searchParams && searchParams.get("code");
|
||||||
@@ -77,6 +78,20 @@ const Home = () => {
|
|||||||
refreshSession(characters).then(saveCharacters).then(setCharacters);
|
refreshSession(characters).then(saveCharacters).then(setCharacters);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleCompactMode = () => {
|
||||||
|
setCompactMode(!compactMode);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const storedCompactMode = localStorage.getItem("compactMode");
|
||||||
|
if (!storedCompactMode) return;
|
||||||
|
storedCompactMode === "true" ? setCompactMode(true) : false;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem("compactMode", compactMode ? "true" : "false");
|
||||||
|
}, [compactMode]);
|
||||||
|
|
||||||
// Initialize EVE PI
|
// Initialize EVE PI
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("api/env")
|
fetch("api/env")
|
||||||
@@ -103,6 +118,8 @@ const Home = () => {
|
|||||||
refreshSession,
|
refreshSession,
|
||||||
EVE_SSO_CALLBACK_URL: environment?.EVE_SSO_CALLBACK_URL ?? "",
|
EVE_SSO_CALLBACK_URL: environment?.EVE_SSO_CALLBACK_URL ?? "",
|
||||||
EVE_SSO_CLIENT_ID: environment?.EVE_SSO_CLIENT_ID ?? "",
|
EVE_SSO_CLIENT_ID: environment?.EVE_SSO_CLIENT_ID ?? "",
|
||||||
|
compactMode,
|
||||||
|
toggleCompactMode,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CharacterContext.Provider
|
<CharacterContext.Provider
|
||||||
|
Reference in New Issue
Block a user