Skip to content

Commit

Permalink
Add logics for picking random name
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallku committed Dec 4, 2024
1 parent 82e9e8f commit 8eacc8f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
19 changes: 14 additions & 5 deletions apps/blog/src/components/CommentForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import { FormEventHandler, useCallback, useRef, useState } from "react";
import { MutateOptions } from "@tanstack/react-query";
import Typography from "@marshallku/ui/Typography";
import Input from "@marshallku/ui/Input";
import Textarea from "@marshallku/ui/Textarea";
import { Icon } from "@marshallku/icon";
import { classNames } from "@marshallku/utils";
import { classNames, generateRandomName } from "@marshallku/utils";
import { type CommentRequest } from "#api";
import CommentAvatar from "#components/CommentAvatar";
import styles from "./index.module.scss";
import { toast } from "@marshallku/toast";
import Button from "@marshallku/ui/Button";

interface CommentFormProps {
slug: string;
Expand All @@ -21,7 +21,7 @@ interface CommentFormProps {
const cx = classNames(styles, "comment-form");

function CommentForm({ slug, submit, isClientSide = false }: CommentFormProps) {
const [name, setName] = useState("");
const [name, setName] = useState("익명");
const [body, setBody] = useState("");
const formRef = useRef<HTMLFormElement>(null);

Expand Down Expand Up @@ -83,12 +83,21 @@ function CommentForm({ slug, submit, isClientSide = false }: CommentFormProps) {
<Input
className={cx("__input")}
name="name"
placeholder="이름 (미입력시 '익명')"
placeholder="이름"
value={name}
onChange={({ currentTarget: { value } }) => {
setName(value);
}}
/>
>
<Button
size="small"
onClick={() => {
setName(generateRandomName());
}}
>
무작위 생성
</Button>
</Input>
<Input className={cx("__input")} name="url" inputMode="url" placeholder="웹사이트" />
<Textarea
className={cx("__textarea")}
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export { default as classNames } from "./lib/classNames";
export * from "./lib/date";
export * from "./lib/object";
export * from "./lib/query";
export * from "./lib/random";
export { default as to } from "./lib/to";
export * from "./lib/url";
52 changes: 52 additions & 0 deletions packages/utils/src/lib/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
export const pickRandom = <T>(array: T[]): T => array[Math.floor(Math.random() * array.length)];

export const generateRandomName = () => {
const adjectives = [
"빠른",
"느린",
"큰",
"작은",
"아름다운",
"멋진",
"귀여운",
"똑똑한",
"게으른",
"용감한",
"겁많은",
"행복한",
"슬픈",
"재미있는",
"지루한",
"친절한",
"사나운",
"순한",
];

const animals = [
"호랑이",
"사자",
"곰",
"토끼",
"여우",
"늑대",
"고양이",
"강아지",
"코끼리",
"기린",
"원숭이",
"팬더",
"소",
"양",
"닭",
"돼지",
"오리",
"뱀",
"개구리",
"물고기",
];

const randomAdjective = pickRandom(adjectives);
const randomAnimal = pickRandom(animals);

return `${randomAdjective} ${randomAnimal}`;
};

1 comment on commit 8eacc8f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visual regression test result - success

Component Story Success Viewport MisMatch Percentage
components-button string-children phone 0.00%
components-button string-children tablet 0.09%
input-input default phone 0.00%
input-input default tablet 0.00%
input-input line phone 0.00%
input-input line tablet 0.00%
input-input box phone 0.00%
input-input box tablet 0.00%
input-textarea line phone 0.00%
input-textarea line tablet 0.00%
input-textarea box phone 0.00%
input-textarea box tablet 0.00%
typography-typography default phone 0.00%
typography-typography default tablet 0.00%

Please sign in to comment.