Skip to content

Commit

Permalink
feat : convert profileurl to pass as prop
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTheKorean committed Nov 23, 2024
1 parent e18441c commit bedb21c
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 72 deletions.
11 changes: 10 additions & 1 deletion src/components/Aside/Aside.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
aside {
position: sticky;
position: sticky; /* Make the aside sticky */
top: 20px; /* Adjust this value to control when the sidebar becomes sticky */
width: 250px; /* Adjust the width as needed */
height: calc(100vh - 40px); /* Full viewport height minus top/bottom padding */
overflow-y: auto; /* Allow vertical scrolling inside the aside */
}

.cohort {
display: flex;
justify-content: flex-end;
}

.container {
Expand Down
25 changes: 17 additions & 8 deletions src/components/Aside/Aside.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react";
import Aside from "./Aside";
import { Grade } from "../../api/services/common/types.ts";

const meta = {
component: Aside,
Expand All @@ -10,11 +11,14 @@ export default meta;
export const Default: StoryObj<typeof meta> = {
args: {
githubUsername: "testuser",
easyTasks: "10",
mediumTasks: "5",
hardTasks: "2",
solvedTasks: 17,
totalTasks: 30,
easyTasks: "5/10",
mediumTasks: "8/10",
hardTasks: "3/5",
solvedTasks: 16,
totalTasks: 25,
profile_url: "https://example.com/profile.jpg", // Provide a valid URL or mock
cohort: 3,
grade: Grade.SMALL_TREE, // Assign an appropriate grade here
},
};

Expand All @@ -23,16 +27,21 @@ export const HighProgress: StoryObj<typeof meta> = {
...Default.args,
solvedTasks: 28,
totalTasks: 30,
easyTasks: "10/10",
mediumTasks: "10/10",
hardTasks: "8/10",
grade: Grade.BIG_TREE, // Higher grade for more progress
},
};

export const NoTasks: StoryObj<typeof meta> = {
args: {
...Default.args,
easyTasks: "0",
mediumTasks: "0",
hardTasks: "0",
easyTasks: "0/0",
mediumTasks: "0/0",
hardTasks: "0/0",
solvedTasks: 0,
totalTasks: 0,
grade: Grade.SEED, // Minimal grade due to no tasks solved
},
};
44 changes: 19 additions & 25 deletions src/components/Aside/Aside.test.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
import { test, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import Aside from "./Aside";
import { Grade } from "../../api/services/common/types.ts";

test("renders the Aside component", () => {
render(
<Aside
githubUsername="testuser"
easyTasks="10"
mediumTasks="5"
hardTasks="2"
easyTasks="10/15"
mediumTasks="5/10"
hardTasks="2/5"
solvedTasks={17}
totalTasks={30}
profile_url="https://example.com/profile.jpg"
cohort={3}
grade={Grade.SMALL_TREE}
/>,
);

const aside = screen.getByRole("complementary");
expect(aside).toBeInTheDocument();
});

test("displays the number of solved tasks", () => {
render(
<Aside
githubUsername="testuser"
easyTasks="10"
mediumTasks="5"
hardTasks="2"
solvedTasks={17}
totalTasks={30}
/>,
);

const solvedTasksText = screen.getByText(/17 문제/i);
expect(solvedTasksText).toBeInTheDocument();
});

test("displays the username", () => {
render(
<Aside
githubUsername="testuser"
easyTasks="10"
mediumTasks="5"
hardTasks="2"
easyTasks="10/15"
mediumTasks="5/10"
hardTasks="2/5"
solvedTasks={17}
totalTasks={30}
profile_url="https://example.com/profile.jpg"
cohort={3}
grade={Grade.SMALL_TREE}
/>,
);

Expand All @@ -54,11 +45,14 @@ test("renders the button link with the text", () => {
render(
<Aside
githubUsername="testuser"
easyTasks="10"
mediumTasks="5"
hardTasks="2"
easyTasks="10/15"
mediumTasks="5/10"
hardTasks="2/5"
solvedTasks={17}
totalTasks={30}
profile_url="https://example.com/profile.jpg"
cohort={3}
grade={Grade.SMALL_TREE}
/>,
);

Expand Down
32 changes: 27 additions & 5 deletions src/components/Aside/Aside.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useEffect } from "react";
import styles from "./Aside.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 { Grade } from "../../api/services/common/types.ts";

interface AsideProps {
githubUsername: string;
Expand All @@ -8,15 +13,29 @@ interface AsideProps {
hardTasks: string;
solvedTasks: number;
totalTasks: number;
profile_url: string;
cohort: number;
grade: Grade;
}

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


export default function Aside({
githubUsername,
easyTasks,
mediumTasks,
hardTasks,
solvedTasks,
totalTasks,
profile_url,
cohort,
grade,
}: AsideProps) {
const progressPercent = Math.min((solvedTasks / totalTasks) * 100, 100);

Expand All @@ -28,23 +47,25 @@ export default function Aside({
}, [progressPercent]);

return (
<aside>
<aside >
<div className={styles.container}>
<span className={styles.cohort}>{cohort}</span>
<section className={styles.profile}>
<div className={styles.avatar}>
<div className={styles["progress-circle"]}></div>
<img src="/SampleImg.png" alt="User's profile picture" />
<img src={profile_url} alt="User's profile picture" />
</div>
<div className={styles.progress}>
<span>{solvedTasks} 문제</span>
<div>PR 리스트</div>
<a href={`https://github.com/DaleStudy/leetcode-study/pulls?q=is%3Apr+author%3A${githubUsername}`}>
풀이 보기
</a>
</div>
<p className={styles.username}>{githubUsername}</p>
</section>

<section className={styles.currentStatus}>
<figure>
<img src="image_url" alt="현재 등급 아이콘" />
<img src={imageTable[grade]} alt={`${grade} 등급`} />
</figure>
</section>
<section className={styles.taskCounts}>
Expand All @@ -68,3 +89,4 @@ export default function Aside({
</aside>
);
}

33 changes: 13 additions & 20 deletions src/components/Progress/Progress.test.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import { beforeEach, describe, expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
import Progress from "./Progress"; // Adjust the import path as needed
import { render, screen, waitFor } from "@testing-library/react";
import Progress from "./Progress";
import { mock } from "vitest-mock-extended";
import useMembers from "../../hooks/useMembers";
import { test, vi } from "vitest";

describe("<Progress/>", () => {
beforeEach(() => render(<Progress />));
vi.mock("../../hooks/useMembers");

it("renders the table", () => {
const table = screen.getByRole("table");
expect(table).toBeInTheDocument();
});
test("render the site header", () => {
vi.mocked(useMembers).mockReturnValue(
mock({ isLoading: false, error: null, members: [] }),
);

it("renders the page header", () => {
const header = screen.getByRole("banner");
expect(header).toBeInTheDocument();
});
render(<Progress />);

it("renders the title", () => {
const heading = screen.getByRole("heading", { level: 1 });
expect(heading).toHaveTextContent("풀이 현황");
});

it("renders footer", () => {
expect(screen.getByRole("contentinfo"));
});
const header = screen.getByRole("banner");
expect(header).toBeInTheDocument();
});
53 changes: 40 additions & 13 deletions src/components/Progress/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,48 @@ import Aside from "../Aside/Aside";
import Footer from "../Footer/Footer";
import Header from "../Header/Header";
import Table from "../Table/Table";

import { problems } from "../../constants/problems";
import { getMembers } from "../../api/services/store/storeService";
import useMembers from "../../hooks/useMembers";

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

export default function Progress() {
const { members, isLoading, error } = useMembers({ getMembers });
console.log({ members, isLoading, error });



const memberId = new URL(location.href).searchParams.get("member"); // Using URL to fetch member ID

if (isLoading) return <p>Loading...</p>; // TODO replace with a proper loading component
if (error) return <p>Error!</p>; // TODO replace with a proper error component

const member = members.find((m) => m.id === memberId);
if (!member) return <p>Member not found!</p>;

const githubUsername = "exampleUser";
const easyTasks = "5/10";
const mediumTasks = "3/10";
const hardTasks = "1/10";
const solvedTasks = 30;
const totalTasks = 30;
// Calculate total tasks dynamically
const totalTasks = problems.length;
const easyProblemsCount = problems.filter((problem) => problem.difficulty === "easy").length;
const mediumProblemsCount = problems.filter((problem) => problem.difficulty === "medium").length;
const hardProblemsCount = problems.filter((problem) => problem.difficulty === "hard").length;

const problems = [
const easySolved = member.solvedProblems.filter((p) => p.difficulty === "easy").length;
const mediumSolved = member.solvedProblems.filter((p) => p.difficulty === "medium").length;
const hardSolved = member.solvedProblems.filter((p) => p.difficulty === "hard").length;
const totalSolved = member.solvedProblems.length;

const easyTasks = `${easySolved}/${easyProblemsCount}`;
const mediumTasks = `${mediumSolved}/${mediumProblemsCount}`;
const hardTasks = `${hardSolved}/${hardProblemsCount}`;

const grade = member.grade

const cohort = member.cohort;

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

//TODO: need to pass the right member
const mockProblems = [
{
id: 128,
title: "Longest Consecutive Sequence",
Expand All @@ -42,19 +66,22 @@ export default function Progress() {
<h1>풀이 현황</h1>
<div className={styles.container}>
<section aria-labelledby="profile">
{/* Pass required props to Aside */}

<Aside
githubUsername={githubUsername}
githubUsername={member.name}
easyTasks={easyTasks}
mediumTasks={mediumTasks}
hardTasks={hardTasks}
solvedTasks={solvedTasks}
solvedTasks={totalSolved}
totalTasks={totalTasks}
profile_url={profile_url}
cohort = {cohort}
grade = {grade}
/>
</section>

<section className={styles.problemList} aria-labelledby="problem-list">
<Table problems={problems} />
<Table problems={mockProblems} />
</section>
</div>

Expand Down

0 comments on commit bedb21c

Please sign in to comment.