Skip to content

Commit

Permalink
Merge pull request #233 from gvorbeck/name-change
Browse files Browse the repository at this point in the history
Name change
  • Loading branch information
gvorbeck authored Jan 29, 2024
2 parents 2e2cf9e + 636f3ed commit 7e6901c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"bfrpgEdition": "4th",
"bfrpgRelease": "137",
"license": "CC BY-SA 4.0",
"version": "2.0.9",
"version": "2.1.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/AvatarPicker/AvatarPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function AvatarPicker({
fileList={fileList}
onPreview={handlePreview}
onChange={handleChange}
className="mt-4 cursor-pointer"
className="cursor-pointer"
>
{fileList.length >= 1 ? null : uploadButton}
</Upload>
Expand Down
39 changes: 33 additions & 6 deletions src/components/PageCharacterSheet/Hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { CharacterDataContext } from "@/contexts/CharacterContext";
import { classSplit } from "@/support/classSupport";
import ExperiencePoints from "./ExperiencePoints/ExperiencePoints";
import HeroAvatar from "./HeroAvatar/HeroAvatar";
import Section from "../Section/Section";
import StepDetails from "@/components/PageNewCharacter/StepDetails/StepDetails";

interface HeroProps {
setModalIsOpen: (modalIsOpen: boolean) => void;
Expand All @@ -32,6 +34,7 @@ const Hero: React.FC<HeroProps & React.ComponentPropsWithRef<"div">> = ({
}) => {
const { character, setCharacter, userIsOwner, uid, id } =
React.useContext(CharacterDataContext);
const [newNameInput, setNewNameInput] = React.useState(character.name);

const heroClassNames = classNames("w-full", className);

Expand All @@ -57,6 +60,16 @@ const Hero: React.FC<HeroProps & React.ComponentPropsWithRef<"div">> = ({
{ key: "3", label: "Class", children: classArr.join(", ") },
];

React.useEffect(() => {
setNewNameInput(character.name);
}, [character.name]);

React.useEffect(
() => setCharacter({ ...character, name: newNameInput }),
// eslint-disable-next-line react-hooks/exhaustive-deps
[newNameInput],
);

return (
<>
<Flex className={heroClassNames} gap={16} vertical>
Expand All @@ -70,12 +83,26 @@ const Hero: React.FC<HeroProps & React.ComponentPropsWithRef<"div">> = ({
setCharacter={setCharacter}
/>
{/* Name */}
<Typography.Title
level={2}
className="text-center m-0 leading-none font-enchant text-5xl tracking-wide w-full"
>
{character.name}
</Typography.Title>
<Section
component={
<Typography.Title
level={2}
className="text-center m-0 leading-none font-enchant text-5xl tracking-wide w-full [&:hover_span]:opacity-100 [&_span]:opacity-50 [&>*]:cursor-pointer!"
>
{character.name}
</Typography.Title>
}
editable
editableComponent={
<StepDetails
character={character}
setCharacter={setCharacter}
className="mr-4"
/>
}
className="relative"
editableClassName="absolute left-full"
/>
<Divider />
<Flex
gap={16}
Expand Down
16 changes: 11 additions & 5 deletions src/components/PageCharacterSheet/Section/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Button, Flex, Tooltip, Typography } from "antd";
import React from "react";
import HelpTooltip from "@/components/HelpTooltip/HelpTooltip";
import { EditOutlined } from "@ant-design/icons";
import classNames from "classnames";

interface SectionProps {
component: React.ReactNode;
title: string;
title?: string;
titleHelpText?: string;
editableComponent?: React.ReactNode;
editableClassName?: string;
editable?: boolean;
}

Expand All @@ -18,8 +20,10 @@ const Section: React.FC<SectionProps & React.ComponentPropsWithRef<"div">> = ({
titleHelpText,
editable,
editableComponent,
editableClassName,
}) => {
const [isEditing, setIsEditing] = React.useState<boolean>(false);
const editOutlinedÇlassNames = classNames("shadow-none", editableClassName);

const handleEditClick = () => {
const editing = !isEditing;
Expand All @@ -29,16 +33,18 @@ const Section: React.FC<SectionProps & React.ComponentPropsWithRef<"div">> = ({
return (
<Flex vertical className={className}>
<Flex gap={16} align="baseline">
<Typography.Title level={3} className="mt-0 leading-none">
{title}
</Typography.Title>
{title && (
<Typography.Title level={3} className="mt-0 leading-none">
{title}
</Typography.Title>
)}
{editable && (
<Tooltip title={isEditing ? "Save" : "Edit"}>
<Button
type={isEditing ? "primary" : "link"}
icon={<EditOutlined className="cursor" />}
onClick={handleEditClick}
className="shadow-none"
className={editOutlinedÇlassNames}
/>
</Tooltip>
)}
Expand Down
9 changes: 6 additions & 3 deletions src/components/PageNewCharacter/StepDetails/StepDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ import { CharData } from "@/data/definitions";
interface StepDetailsProps {
character: CharData;
setCharacter: (character: CharData) => void;
newCharacter?: boolean;
}

const StepDetails: React.FC<
StepDetailsProps & React.ComponentPropsWithRef<"div">
> = ({ className, character, setCharacter }) => {
> = ({ className, character, setCharacter, newCharacter }) => {
const handleNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const cleanInput = DOMPurify.sanitize(event.target.value);
setCharacter({ ...character, name: cleanInput });
};

return (
<Flex vertical className={className}>
<Flex vertical className={className} gap={16}>
<Input
value={character.name}
onChange={handleNameChange}
placeholder="Name"
/>
<AvatarPicker character={character} setCharacter={setCharacter} />
{newCharacter && (
<AvatarPicker character={character} setCharacter={setCharacter} />
)}
</Flex>
);
};
Expand Down
8 changes: 7 additions & 1 deletion src/support/pageNewCharacterSupport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ export const getStepsItems = (
title: "Name",
fulltitle: "Name Your Character",
description: newCharacterStepDescriptions.name,
content: <StepDetails character={character} setCharacter={setCharacter} />,
content: (
<StepDetails
character={character}
setCharacter={setCharacter}
newCharacter
/>
),
},
];

Expand Down

0 comments on commit 7e6901c

Please sign in to comment.