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

feat: Profile name or image click behavior in comments. #383 #386

Merged
merged 1 commit into from
Aug 4, 2024
Merged
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
15 changes: 13 additions & 2 deletions src/components/Article/DiscussionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect, FormEvent } from "react";
import { Box, TextField, Button, Typography, Avatar } from "@mui/material";
import { getDatabase, ref, set, onValue, get } from "firebase/database";
import moment from "moment";
import { Link } from "react-router-dom";

const modalStyle = {
borderTop: "1px solid rgba(0, 0, 0, 0.189)",
Expand All @@ -12,6 +13,7 @@ const modalStyle = {
interface User {
name: string;
pic: string;
uid: string;
}

interface CommentData {
Expand All @@ -20,6 +22,7 @@ interface CommentData {
avatar: string;
content: string;
timestamp: string;
authoruid: string;
}

interface DiscussionModalProps {
Expand Down Expand Up @@ -52,6 +55,7 @@ const DiscussionModal: React.FC<DiscussionModalProps> = ({
setUser({
name: userData.name || "Guest User",
pic: userData.pic || placeholderAvatar,
uid: userData.uid || "",
});
}
} catch (error) {
Expand Down Expand Up @@ -115,6 +119,7 @@ const DiscussionModal: React.FC<DiscussionModalProps> = ({
id: newCommentId,
author: user.name,
avatar: user.pic,
authoruid: user.uid,
content: newComment,
timestamp: new Date().toISOString(),
};
Expand Down Expand Up @@ -182,9 +187,15 @@ const Comment: React.FC<CommentProps> = ({ data }) => {
return (
<Box mt={2} borderBottom="1px solid #ddd" pb={2}>
<Box display="flex" alignItems="center" className="header_comment">
<Avatar src={data.avatar || placeholderAvatar} alt={data.author} />
<Link to={`/profile/${data.authoruid}`}>
{" "}
<Avatar src={data.avatar || placeholderAvatar} alt={data.author} />
</Link>
<Box ml={2}>
<Typography variant="subtitle2">{data.author}</Typography>
<Link className="article_link" to={`/profile/${data.authoruid}`}>
{" "}
<Typography variant="subtitle2">{data.author}</Typography>
</Link>
<Typography variant="caption" color="textSecondary">
{moment(data.timestamp).fromNow()}
</Typography>
Expand Down