Skip to content

Commit

Permalink
Merge pull request #646 from bounswe/feature/frontend/followed-tags-i…
Browse files Browse the repository at this point in the history
…n-profile
  • Loading branch information
mmtftr authored Dec 9, 2024
2 parents 8da7d47 + d9cc470 commit 07f6fa6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
25 changes: 23 additions & 2 deletions frontend/src/routes/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import useAuthStore from "@/services/auth";
import { useEffect, useRef, useState } from "react";
import { Link, useParams } from "react-router-dom";

import { Badge } from "@/components/ui/badge";
import { Textarea } from "@/components/ui/textarea";

export default function Profile() {
Expand Down Expand Up @@ -83,10 +84,10 @@ export default function Profile() {
/>
</Avatar>
<div className="flex space-x-4 text-center">
{/* <div>
<div>
<div className="font-bold">{profile.questionCount}</div>
<div className="text-sm text-gray-700">Questions</div>
</div> */}
</div>
<div>
<div className="font-bold">{profile.answerCount}</div>
<div className="text-sm text-gray-700">Answers</div>
Expand Down Expand Up @@ -166,6 +167,26 @@ export default function Profile() {
)
)}
</div>
{profile.followedTags && (
<div className="flex flex-col">
<div className="flex flex-wrap gap-2">
<span className="flex items-center gap-2">
<span>Followed tags: </span>
{profile.followedTags
?.map((s) => (
<Link to={`/tag/${s.id}`} key={s.name}>
<Badge>{s.name}</Badge>
</Link>
))
.slice(0, 3)}
{profile.followedTags?.length &&
profile.followedTags?.length > 3 && (
<span>+ {profile.followedTags?.length - 3} more</span>
)}
</span>
</div>
</div>
)}
</div>
<div className="mt-4 flex flex-col gap-4 px-4 py-2">
<Tabs value={activeTab} onValueChange={setActiveTab}>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/routes/question.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ const mockQuestionData = vi.hoisted(
createdAt: "2023-01-01T00:00:00Z",
updatedAt: "2023-01-01T00:00:00Z",
dislikeCount: 0,
bookmarked: false,
selfVoted: 1,
selfDifficultyVote: "EASY",
easyCount: 5,
mediumCount: 3,
hardCount: 2,
bookmarked: false, // Add this property
selfVoted: 0, // Add this property (e.g., 0 for no vote, 1 for upvote, -1 for downvote)
selfDifficultyVote: false,
}) satisfies QuestionDetails,
);
// Mock the API hook
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/routes/question.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import LinkIcon from "@/assets/Icon/General/Link.svg?react";
import { Answers } from "@/components/Answers";
import { ContentWithSnippets } from "@/components/ContentWithSnippets";
import { CreateAnswerForm } from "@/components/CreateAnswerForm";
import { DifficultyBar } from "@/components/DifficultyBar";
import ErrorAlert from "@/components/ErrorAlert";
import { ExerciseCard } from "@/components/ExerciseCard";
import FollowButton from "@/components/FollowButton";
Expand All @@ -19,8 +21,6 @@ import { convertTagToTrack, useExercismSearch } from "@/services/exercism";
import { Flag, MessageSquare, ThumbsDown, ThumbsUp, Trash } from "lucide-react";
import { useState } from "react";
import { Link, useParams } from "react-router-dom";
import { ContentWithSnippets } from "@/components/ContentWithSnippets";
import { DifficultyBar } from "@/components/DifficultyBar";

export default function QuestionPage() {
const { questionId } = useParams();
Expand Down Expand Up @@ -76,7 +76,7 @@ export default function QuestionPage() {
difficulty:
(data as unknown as { difficultyLevel: string })?.difficultyLevel ??
"easy",
track: convertTagToTrack(data?.tags[0].name ?? ""),
track: convertTagToTrack(data?.tags?.[0]?.name ?? ""),
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/services/api/programmingForumSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export type UserProfile = {
answerCount?: number;
answers?: AnswerDetails[];
questions?: QuestionSummary[];
followedTags?: TagSummary[];
};

export type UserProfileUpdate = {
Expand Down Expand Up @@ -150,7 +151,7 @@ export type QuestionDetails = {
* @maximum 1
*/
selfVoted: number;
selfDifficultyVote: boolean;
selfDifficultyVote: DifficultyLevel;
easyCount: number;
mediumCount: number;
hardCount: number;
Expand Down Expand Up @@ -261,6 +262,7 @@ export type TagDetails = {
export type TagSummary = {
id?: string;
name?: string;
tagType?: TagType;
questionCount?: number;
/**
* @format url
Expand Down
4 changes: 3 additions & 1 deletion mobile/services/api/programmingForumSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export type UserProfile = {
answerCount?: number;
answers?: AnswerDetails[];
questions?: QuestionSummary[];
followedTags?: TagSummary[];
};

export type UserProfileUpdate = {
Expand Down Expand Up @@ -150,7 +151,7 @@ export type QuestionDetails = {
* @maximum 1
*/
selfVoted: number;
selfDifficultyVote: boolean;
selfDifficultyVote: DifficultyLevel;
easyCount: number;
mediumCount: number;
hardCount: number;
Expand Down Expand Up @@ -261,6 +262,7 @@ export type TagDetails = {
export type TagSummary = {
id?: string;
name?: string;
tagType?: TagType;
questionCount?: number;
/**
* @format url
Expand Down
8 changes: 7 additions & 1 deletion swagger/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,10 @@ components:
type: array
items:
$ref: "#/components/schemas/QuestionSummary"
followedTags:
type: array
items:
$ref: "#/components/schemas/TagSummary"
examples:
- id: 1
username: "john_doe"
Expand Down Expand Up @@ -1447,7 +1451,7 @@ components:
minimum: -1
maximum: 1
selfDifficultyVote:
type: boolean
$ref: "#/components/schemas/DifficultyLevel"
easyCount:
type: integer
mediumCount:
Expand Down Expand Up @@ -1709,6 +1713,8 @@ components:
type: string
name:
type: string
tagType:
$ref: '#/components/schemas/TagType'
questionCount:
type: integer
photo:
Expand Down

0 comments on commit 07f6fa6

Please sign in to comment.