Skip to content

Commit

Permalink
update: apply feedback:
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTheKorean committed Dec 2, 2024
1 parent 5667acc commit b712541
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 140 deletions.
47 changes: 0 additions & 47 deletions src/components/Aside/Aside.stories.tsx

This file was deleted.

63 changes: 0 additions & 63 deletions src/components/Aside/Aside.test.tsx

This file was deleted.

15 changes: 7 additions & 8 deletions src/components/Progress/Progress.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Aside from "../Aside/Aside";
import Sidebar from "../Sidebar/Sidebar";
import Footer from "../Footer/Footer";
import Header from "../Header/Header";
import Table from "../Table/Table";
import { getMembers } from "../../api/getMembers";
import { problems } from "../../constants/problems";
import { problemMap, problemCounts } from "../../constants/problems";


import useMembers from "../../hooks/useMembers";
import styles from "./Progress.module.css";

Expand All @@ -22,7 +21,7 @@ export default function Progress() {
const member = members.find((m) => m.id === memberId);
if (!member) return <p>Member not found!</p>;

const totalTasks = Object.values(problemMap).length;
const totalProblems = Object.values(problemMap).length;
const {
easy: easyProblemsCount,
medium: mediumProblemsCount,
Expand Down Expand Up @@ -51,7 +50,7 @@ export default function Progress() {

const { grade, cohort } = member;

const profile_url = member.profileUrl || "Logo.png";
const profileUrl = member.profileUrl || "Logo.png";

// To be updated, this will be replaced by the real data in a seperate pr.
const mockedProblems = [
Expand Down Expand Up @@ -81,14 +80,14 @@ export default function Progress() {
<h1>풀이 현황</h1>
<div className={styles.container}>
<section aria-labelledby="profile">
<Aside
<Sidebar
githubUsername={member.name}
easyProgress={easyProgress}
mediumProgress={mediumProgress}
hardProgress={hardProgress}
solvedTasks={totalSolved}
totalTasks={totalTasks}
profile_url={profile_url}
solvedProblems={totalSolved}
totalProblems={totalProblems}
profileUrl={profileUrl}
cohort={cohort}
grade={grade}
/>
Expand Down
File renamed without changes.
44 changes: 44 additions & 0 deletions src/components/Sidebar/Sidebar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Meta, StoryObj } from "@storybook/react";
import Sidebar from "./Sidebar.tsx";
import { Grade } from "../../api/services/types";

const meta = {
component: Sidebar,
args: {
githubUsername: "testuser",
easyProgress: "5/10",
mediumProgress: "8/10",
hardProgress: "3/5",
solvedProblems: 16,
totalProblems: 25,
profileUrl: "https://avatars.githubusercontent.com/u/104721736?v=4",
cohort: 3,
grade: Grade.LEAF,
},
} satisfies Meta<typeof Sidebar>;

export default meta;

export const Default: StoryObj<typeof meta> = {};

export const HighProgress: StoryObj<typeof meta> = {
args: {
solvedProblems: 28,
totalProblems: 30,
easyProgress: "10/10",
mediumProgress: "10/10",
hardProgress: "8/10",
grade: Grade.FRUIT,
},
};

export const NoProblems: StoryObj<typeof meta> = {
args: {
easyProgress: "0/0",
mediumProgress: "0/0",
hardProgress: "0/0",
solvedProblems: 0,
totalProblems: 0,
grade: Grade.SEED,
},
};
34 changes: 34 additions & 0 deletions src/components/Sidebar/Sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { test, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import Sidebar from "./Sidebar.tsx";
import { Grade } from "../../api/services/types";

test("renders Sidebar with all elements", () => {
render(
<Sidebar
githubUsername="testuser"
easyProgress="10/15"
mediumProgress="5/10"
hardProgress="2/5"
solvedProblems={17}
totalProblems={30}
profileUrl="example.png"
cohort={3}
grade={Grade.TREE}
/>,
);

// Check if the sidebar exists
const sidebar = screen.getByRole("complementary");
expect(sidebar).toBeInTheDocument();

// Check if the username is displayed
const username = screen.getByText(/testuser/i);
expect(username).toBeInTheDocument();

// Check if the button link exists
const buttonLink = screen.getByRole("link", {
name: /리더보드로 돌아가기/i,
});
expect(buttonLink).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
import { useEffect } from "react";
import styles from "./Aside.module.css";
import { useEffect, useRef } from "react";
import styles from "./Sidebar.module.css";
import Seed from "../../assets/Seed.png";
import Sprout from "../../assets/Sprout.png";
import YoungTree from "../../assets/YoungTree.png";
import LargeTree from "../../assets/LargeTree.png";
import Github from "../../assets/Github.png";
import { Grade } from "../../api/services/common/types.ts";
import { Grade } from "../../api/services/types";

interface AsideProps {
interface SidebarProps {
githubUsername: string;
easyProgress: string;
mediumProgress: string;
hardProgress: string;
solvedTasks: number;
totalTasks: number;
profile_url: string;
solvedProblems: number;
totalProblems: number;
profileUrl: string;
cohort: number;
grade: Grade;
}

const imageTable = {
SEED: Seed,
SPROUT: Sprout,
SMALL_TREE: YoungTree,
BIG_TREE: LargeTree,
LEAF: Sprout,
BRANCH: Sprout,
FRUIT: YoungTree,
TREE: LargeTree,
};

export default function Aside({
export default function Sidebar({
githubUsername,
easyProgress,
mediumProgress,
hardProgress,
solvedTasks,
totalTasks,
profile_url,
solvedProblems,
totalProblems,
profileUrl,
cohort,
grade,
}: AsideProps) {
const progressPercent = Math.min((solvedTasks / totalTasks) * 100, 100);
}: SidebarProps) {
const progressContainerRef = useRef<HTMLDivElement>(null);
const progressPercent = Math.min((solvedProblems / totalProblems) * 100, 100);

useEffect(() => {
document.documentElement.style.setProperty(
"--progress",
`${progressPercent}%`,
);
if (progressContainerRef.current) {
progressContainerRef.current.style.setProperty(
"--progress",
`${progressPercent}%`,
);
}
}, [progressPercent]);

const taskProgress = [
Expand All @@ -54,15 +59,15 @@ export default function Aside({

return (
<aside>
<div className={styles.container}>
<div className={styles.container} ref={progressContainerRef}>
<span className={styles.cohort}>{cohort}</span>
<section className={styles.profile}>
<div className={styles.avatar}>
<div className={styles["progress-circle"]}></div>
<img src={profile_url} alt="User's profile picture" />
<img src={profileUrl} alt="User's profile picture" />
</div>
<div>
<span className={styles.gradientText}>{solvedTasks} </span>
<span className={styles.gradientText}>{solvedProblems} </span>
<span className={styles.solidText}> 문제</span>
</div>
<div className={styles.progress}>
Expand Down

0 comments on commit b712541

Please sign in to comment.