Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend] Followed tags in profile #646

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 6 additions & 0 deletions frontend/src/routes/question.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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: 0,
hardCount: 0,
mediumCount: 0,
}) satisfies QuestionDetails,
);
// Mock the API hook
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/question.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 ErrorAlert from "@/components/ErrorAlert";
import { ExerciseCard } from "@/components/ExerciseCard";
Expand All @@ -19,7 +20,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";

export default function QuestionPage() {
const { questionId } = useParams();
Expand Down Expand Up @@ -75,7 +75,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