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

add links in profile page #609

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion frontend/src/components/profile/forum-post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { motion } from "framer-motion";
import { IconHeart, IconMessages } from "@tabler/icons-react";
import { timePassed } from "../../utils";
import { useFetchReplies } from "../../hooks/api/get-reply";
import { useNavigate } from "react-router-dom";

export const ForumPostCard = ({ post }: { post: ForumPost }) => {

const navigate = useNavigate();

const { data: replies } = useFetchReplies(post.id);
return (
<motion.div
key={post.id}
className="p-4 transition-colors cursor-pointer bg-purple-50 rounded-xl hover:bg-purple-100"
whileHover={{ scale: 1.01 }}
onClick={() => navigate(`/post/${post.id}`)}
>
<div className="flex items-center justify-between">
<div>
Expand All @@ -21,7 +26,7 @@ export const ForumPostCard = ({ post }: { post: ForumPost }) => {
{timePassed(post.createdAt)}
</p>
</div>
<div className="flex items-center gap-4">
<div onClick={e => e.stopPropagation()} className="flex items-center gap-4">
<div className="flex items-center gap-1">
<IconHeart className="w-5 h-5 text-red-500" />
<span>{post.noUpvote}</span>
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/hooks/api/quiz-favorite/quiz-favorite.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useDeleteQuizFavorite } from "./delete-quiz-favorite";
import { useFetchQuizFavorites } from "./get-quiz-favorite";
import { usePostQuizFavorite } from "./post-quiz-favorite";

export const useQuizFavorite = () => {
const { data: favoriteQuizzes } = useFetchQuizFavorites();
const { mutateAsync: postQuizFavorite } = usePostQuizFavorite();
const { mutateAsync: deleteQuizFavorite } = useDeleteQuizFavorite();

const isQuizFavorite = (quizId: number | undefined) => {
return favoriteQuizzes?.filter(favoriteQuizzes => favoriteQuizzes?.quizId === quizId).length == 1;
}

const handleLikeClick = (quizId: number | undefined) => {
if (!quizId) return;
if (!isQuizFavorite(quizId)) {
postQuizFavorite(quizId);
} else {
deleteQuizFavorite(quizId);
}
};

return { isQuizFavorite, handleLikeClick };
}
14 changes: 10 additions & 4 deletions frontend/src/pages/profile-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import ProfileUpdateModal from "../components/profile/update-modal";

import { message, Spin, Tabs } from "antd";
import { Link, useParams } from "react-router-dom";
import { Link, useNavigate, useParams } from "react-router-dom";
import { useGetProfile } from "../hooks/api/profile/get";
import { useUpdateProfile } from "../hooks/api/profile/update";
import { useFetchQuizzes } from "../hooks/api/get-quizzes";
Expand All @@ -30,6 +30,7 @@ import { usePostFollowing } from "../hooks/api/profile/follow-button/post-follow
import { useDeleteFollowing } from "../hooks/api/profile/follow-button/delete-following";

import { DeleteQuizButton } from "../components/profile/delete-quiz-button";
import { useQuizFavorite } from "../hooks/api/quiz-favorite/quiz-favorite";

const ProfilePage = () => {
const [isModalOpen, setIsModalOpen] = useState(false);
Expand All @@ -51,6 +52,10 @@ const ProfilePage = () => {
const { mutateAsync: followUser } = usePostFollowing();
const { mutateAsync: unfollowUser } = useDeleteFollowing();

const { isQuizFavorite, handleLikeClick } = useQuizFavorite();

const navigate = useNavigate();

const handleFollow = () => {
if (isFollowing) {
unfollowUser(username);
Expand Down Expand Up @@ -230,6 +235,7 @@ const ProfilePage = () => {
key={quiz.id}
className="p-4 transition-colors cursor-pointer bg-purple-50 rounded-xl hover:bg-purple-100"
whileHover={{ scale: 1.01 }}
onClick={() => {navigate("/quiz/" + quiz.id)}}
>
<div className="flex items-center justify-between">
<div>
Expand All @@ -240,11 +246,11 @@ const ProfilePage = () => {
{quiz.questions.length} Questions
</p>
</div>
<div className="flex items-center gap-4">
<div onClick={e => e.stopPropagation()} className="flex items-center gap-4">
<DifficultyBadge difficulty={quiz.difficulty} />
<div className="flex items-center gap-1">
<IconHeart className="w-5 h-5 text-red-500" />
{/* <span>{quiz.likes}</span> */}4
<IconHeart onClick={() => {handleLikeClick(quiz.id)}} className={`w-5 h-5 text-red-500 + ${(isQuizFavorite(quiz && quiz.id) ? "fill-red-500" : "")}`} />
{/* <span>{quiz.likes}</span> */}
</div>
{isOwnProfile && (
<DeleteQuizButton
Expand Down