Add comment field that is shown on account hover. Update discord link

This commit is contained in:
Calli
2023-09-28 16:57:37 +03:00
parent d4e3ed978e
commit d2b66eb193
7 changed files with 47 additions and 28 deletions

View File

@@ -16,9 +16,11 @@ export const CharacterDialog = ({
updateCharacter: (characer: AccessToken, update: CharacterUpdate) => void; updateCharacter: (characer: AccessToken, update: CharacterUpdate) => void;
}) => { }) => {
const [account, setAccount] = useState(""); const [account, setAccount] = useState("");
const [comment, setComment] = useState("");
useEffect(() => { useEffect(() => {
if (character?.account) setAccount(character.account); if (character?.account) setAccount(character.account);
if (character?.comment) setComment(character.comment);
}, [character]); }, [character]);
const logout = (character: AccessToken) => { const logout = (character: AccessToken) => {
@@ -29,8 +31,8 @@ export const CharacterDialog = ({
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => { const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
if (event.key === "Enter") { if (event.key === "Enter") {
character && updateCharacter(character, { account });
closeDialog(); closeDialog();
character && updateCharacter(character, { account, comment });
} }
}; };
@@ -46,10 +48,20 @@ export const CharacterDialog = ({
onChange={(event) => setAccount(event.target.value)} onChange={(event) => setAccount(event.target.value)}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
/> />
<TextField
id="outlined-basic"
label="Comment"
variant="outlined"
value={comment ?? ""}
sx={{ margin: 1 }}
multiline={true}
onChange={(event) => setComment(event.target.value)}
onKeyDown={handleKeyDown}
/>
<DialogActions> <DialogActions>
<Button <Button
onClick={() => { onClick={() => {
character && updateCharacter(character, { account }); character && updateCharacter(character, { account, comment });
closeDialog(); closeDialog();
}} }}
variant="contained" variant="contained"

View File

@@ -7,7 +7,7 @@ import { styled, useTheme } from "@mui/material/styles";
import React from "react"; import React from "react";
import { CharacterDialog } from "./CharacterDialog"; import { CharacterDialog } from "./CharacterDialog";
import { AccessToken } from "@/types"; import { AccessToken } from "@/types";
import { Box, Button } from "@mui/material"; import { Box, Button, Tooltip } from "@mui/material";
import { EVE_IMAGE_URL } from "@/const"; import { EVE_IMAGE_URL } from "@/const";
import { CharacterContext } from "@/app/context/Context"; import { CharacterContext } from "@/app/context/Context";
@@ -38,30 +38,32 @@ export const CharacterRow = ({ character }: { character: AccessToken }) => {
updateCharacter={updateCharacter} updateCharacter={updateCharacter}
closeDialog={() => setSelectedCharacter(undefined)} closeDialog={() => setSelectedCharacter(undefined)}
/> />
<Box <Tooltip title={character.comment}>
display="flex" <Box
flexDirection="column" display="flex"
maxWidth={120} flexDirection="column"
onClick={() => setSelectedCharacter(character)} maxWidth={120}
> onClick={() => setSelectedCharacter(character)}
<Image
src={`${EVE_IMAGE_URL}/characters/${character.character.characterId}/portrait?size=128`}
alt=""
width={theme.custom.cardImageSize}
height={theme.custom.cardImageSize}
style={{ marginBottom: "0.2rem", borderRadius: 8 }}
/>
<Button
style={{
padding: 6,
fontSize: theme.custom.smallText,
lineHeight: 1,
}}
variant="outlined"
> >
{character.character.name} <Image
</Button> src={`${EVE_IMAGE_URL}/characters/${character.character.characterId}/portrait?size=128`}
</Box> alt=""
width={theme.custom.cardImageSize}
height={theme.custom.cardImageSize}
style={{ marginBottom: "0.2rem", borderRadius: 8 }}
/>
<Button
style={{
padding: 6,
fontSize: theme.custom.smallText,
lineHeight: 1,
}}
variant="outlined"
>
{character.character.name}
</Button>
</Box>
</Tooltip>
</StackItem> </StackItem>
); );
}; };

View File

@@ -4,7 +4,7 @@ export const DiscordButton = () => {
<Box> <Box>
<Tooltip title="Come nerd out in discord about PI and this tool"> <Tooltip title="Come nerd out in discord about PI and this tool">
<Button <Button
href="https://discord.gg/MDapvGyw" href="https://discord.gg/qQK7vu3y9"
target="_blank" target="_blank"
style={{ width: "100%" }} style={{ width: "100%" }}
sx={{ color: "white", display: "block" }} sx={{ color: "white", display: "block" }}

View File

@@ -42,6 +42,7 @@ const Home = () => {
return { return {
...c, ...c,
...(updates.account ? { account: updates.account } : {}), ...(updates.account ? { account: updates.account } : {}),
...(updates.comment ? { comment: updates.comment } : {}),
}; };
return c; return c;
}); });

View File

@@ -1,7 +1,7 @@
import { AccessToken } from "@/types"; import { AccessToken } from "@/types";
import { extractCharacterFromToken } from "@/utils"; import { extractCharacterFromToken } from "@/utils";
import { NextApiRequest, NextApiResponse } from "next";
import crypto from "crypto-js"; import crypto from "crypto-js";
import { NextApiRequest, NextApiResponse } from "next";
const EVE_SSO_TOKEN_URL = "https://login.eveonline.com/v2/oauth/token"; const EVE_SSO_TOKEN_URL = "https://login.eveonline.com/v2/oauth/token";
const EVE_SSO_CLIENT_ID = process.env.EVE_SSO_CLIENT_ID ?? ""; const EVE_SSO_CLIENT_ID = process.env.EVE_SSO_CLIENT_ID ?? "";
@@ -46,6 +46,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
character, character,
needsLogin: false, needsLogin: false,
account: accessToken.account, account: accessToken.account,
comment: accessToken.comment
}; };
console.log("Refresh", character.name, character.characterId); console.log("Refresh", character.name, character.characterId);

View File

@@ -47,6 +47,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
character, character,
needsLogin: false, needsLogin: false,
account: "-", account: "-",
comment: "",
}; };
res.json(token); res.json(token);
} else { } else {

View File

@@ -8,6 +8,7 @@ export interface AccessToken {
character: Character; character: Character;
account: string; account: string;
needsLogin: boolean; needsLogin: boolean;
comment: string;
} }
export interface Character { export interface Character {
@@ -28,6 +29,7 @@ export interface CharacterPlanets {
export interface CharacterUpdate { export interface CharacterUpdate {
account?: string; account?: string;
comment?: string;
} }
export type Planet = EsiType<"v1", "getCharactersCharacterIdPlanets">[number]; export type Planet = EsiType<"v1", "getCharactersCharacterIdPlanets">[number];