Skip to content

Commit

Permalink
refactor & bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
0xk4b1r committed Oct 10, 2024
1 parent 95f5842 commit 01a4694
Show file tree
Hide file tree
Showing 28 changed files with 181 additions and 114 deletions.
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"compilerOptions": {
"baseUrl": "."
"baseUrl": ""
}
}
14 changes: 7 additions & 7 deletions src/components/AIChat/AIChat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const AiChat = () => {
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${user.token}`,
Authorization: `Bearer ${user?.token}`,
},
},
);
Expand Down Expand Up @@ -109,7 +109,7 @@ const AiChat = () => {
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${user.token}`,
Authorization: `Bearer ${user?.token}`,
},
},
);
Expand Down Expand Up @@ -144,7 +144,7 @@ const AiChat = () => {
const response = await axios.get(`${API_BASE_URL}/get`, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${user.token}`,
Authorization: `Bearer ${user?.token}`,
},
});
setChats(response.data);
Expand All @@ -160,15 +160,15 @@ const AiChat = () => {
const response = await axios.get(`${API_BASE_URL}/${selectedChatId}`, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${user.token}`,
Authorization: `Bearer ${user?.token}`,
},
});
setChat(response.data);
} catch (error) {
console.error("Error fetching chat:", error);
setFetchError("Failed to load chat. Please try again.");
}
}, [API_BASE_URL, selectedChatId, user.token]);
}, [API_BASE_URL, selectedChatId, user?.token]);

useEffect(() => {
if (!user) return;
Expand Down Expand Up @@ -203,7 +203,7 @@ const AiChat = () => {
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${user.token}`,
Authorization: `Bearer ${user?.token}`,
},
},
);
Expand All @@ -225,7 +225,7 @@ const AiChat = () => {
await axios.delete(`${API_BASE_URL}/delete/${chatId}`, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${user.token}`,
Authorization: `Bearer ${user?.token}`,
},
});

Expand Down
12 changes: 11 additions & 1 deletion src/components/Blogs/BlogCard/BlogCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ import { BsBookmarks, BsBookmarksFill } from "react-icons/bs";
import { addBookmark, removeBookmark } from "src/features/bookmarks/bookmarkSlice.js";

const image = "https://user-images.githubusercontent.com/44284877/210166161-ad2f71a7-df74-43b9-8330-af9740d9e8ba.png";
const darkImage =
"https://thecyberhub-assets.s3.ap-south-1.amazonaws.com/thecyberhub-assets/development/blog/1727036400323.png";

const BlogCard = ({ blog, bookmarks, isDashboard, user }) => {
const dispatch = useDispatch();
const coverImage = blog?.coverImage;
const coverImageUrl = cdnContentImagesUrl(`/blog/${coverImage}`) || image;
const coverErrorImageUrl = darkImage;

const userId = user?._id;

Expand Down Expand Up @@ -72,7 +75,14 @@ const BlogCard = ({ blog, bookmarks, isDashboard, user }) => {
<DetailsSection>
<BlogImageSection>
<RouterLink to={{ pathname: blogURL }}>
<BlogCardImage src={coverImageUrl || image} alt={""} />
<BlogCardImage
src={coverImageUrl || image}
alt="Blog Cover"
onError={(e) => {
e.target.onerror = null;
e.target.src = coverErrorImageUrl;
}}
/>
</RouterLink>
<Username> @{blog?.username}</Username>
</BlogImageSection>
Expand Down
34 changes: 18 additions & 16 deletions src/components/Blogs/Blogs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,24 @@ const Blogs = () => {
wordWrap: "break-word",
}}
>
{categories.map((category, index) => (
<li
key={index}
onClick={() => handleCategoryClick(category)}
style={{
cursor: "pointer",
fontWeight: selectedCategory === category ? "bold" : "normal",
backgroundColor: "#1d1d1d",
padding: "0.5rem 1rem", // Use rem for padding
borderRadius: "5px",
fontSize: "1rem", // Use rem for font size
}}
>
{category}
</li>
))}
{categories.map((category, index) =>
category && category.length > 0 ? (
<li
key={index}
onClick={() => handleCategoryClick(category)}
style={{
cursor: "pointer",
fontWeight: selectedCategory === category ? "bold" : "normal",
backgroundColor: "#1d1d1d",
padding: "0.5rem 1rem",
borderRadius: "5px",
fontSize: "1rem",
}}
>
{category}
</li>
) : null,
)}
</ul>
</header>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ImageInput, useUploadImages } from "src/components/Common/ImageUpload";

const MAX_IMAGE_SIZE_BYTES = 1048576;
const CreateBlogV2 = () => {
const { user } = useSelector((state) => state.auth);
const {
images,
imagesName,
Expand All @@ -42,10 +43,10 @@ const CreateBlogV2 = () => {
maxImageSizeByte: MAX_IMAGE_SIZE_BYTES,
pageName: "blog",
requiredImageWidth: 1280,
user,
});
const dispatch = useDispatch();
const navigate = useNavigate();
const { user } = useSelector((state) => state.auth);
const [showAuthPopup, setShowAuthPopup] = useState(false);
const {
// blogs,
Expand Down
75 changes: 37 additions & 38 deletions src/components/CaptureTheFlag/CTF.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from // ,{useEffect, useState}
"react";
import React from "react"; // ,{useEffect, useState}
import { Wrapper } from "src/components/Dashboard/Profile/ProfileElements";
// import {getAllCTFs} from "src/features/ctf/ctfSlice";
// import {useDispatch, useSelector} from "react-redux";
Expand All @@ -8,8 +7,8 @@ import { CTFContainer, CTFHeader, CTFHeading, Option, SearchContainer, SearchDif
// import UnderMaintenance from "src/components/Other/UnderMaintenance/UnderMaintenance";
// import apiStatus from "src/features/apiStatus";
// import CtfChallenges from "./CTFCards/CtfChallenges";
import { RankTrophy } from "src/components/Header/Navbar/NavbarElements";
import { RouteLink } from "src/components/Common/GeneralDashboardSidebar/GeneralDashboardSidebarElements";
// import { RankTrophy } from "src/components/Header/Navbar/NavbarElements";
// import { RouteLink } from "src/components/Common/GeneralDashboardSidebar/GeneralDashboardSidebarElements";
// import LoadingSpinner from "src/components/Other/MixComponents/Spinner/LoadingSpinner";
import SearchInputBox from "src/components/Common/SearchInputBox";
// import {Link} from "react-router-dom";
Expand Down Expand Up @@ -70,7 +69,7 @@ const CTF = () => {
<CTFHeading> Capture The Flag</CTFHeading>
</CTFHeader>

{/* {user && user.role === 'admin' || user.role === 'team' ? ( */}
{/* {user && user.role === 'admin' || user.role !== 'team' ? ( */}
{/* <Link to={`create`}> */}
{/* <Heading2>Create</Heading2> */}
{/* </Link> */}
Expand Down Expand Up @@ -111,39 +110,39 @@ const CTF = () => {
</Select>
</SearchDifficulty>

<RouteLink to="teams">
<SearchDifficulty
style={{
display: "flex",
justifyContent: "center",
textDecoration: "none",
gap: "5px",
padding: "6px 15px 6px 10px",
borderRadius: "5px",
backgroundColor: "#252525",
}}
>
<RankTrophy style={{ fontSize: "1rem" }} />
<span> Teams </span>
</SearchDifficulty>
</RouteLink>

<RouteLink to="/leaderboard">
<SearchDifficulty
style={{
display: "flex",
justifyContent: "center",
textDecoration: "none",
gap: "5px",
padding: "6px 15px 6px 10px",
borderRadius: "5px",
backgroundColor: "#252525",
}}
>
<RankTrophy style={{ fontSize: "1rem" }} />
<span> Leaderboard </span>
</SearchDifficulty>
</RouteLink>
{/* <RouteLink to="teams"> */}
{/* <SearchDifficulty */}
{/* style={{ */}
{/* display: "flex", */}
{/* justifyContent: "center", */}
{/* textDecoration: "none", */}
{/* gap: "5px", */}
{/* padding: "6px 15px 6px 10px", */}
{/* borderRadius: "5px", */}
{/* backgroundColor: "#252525", */}
{/* }} */}
{/* > */}
{/* <RankTrophy style={{ fontSize: "1rem" }} /> */}
{/* <span> Teams </span> */}
{/* </SearchDifficulty> */}
{/* </RouteLink> */}
{/**/}
{/* <RouteLink to="/leaderboard"> */}
{/* <SearchDifficulty */}
{/* style={{ */}
{/* display: "flex", */}
{/* justifyContent: "center", */}
{/* textDecoration: "none", */}
{/* gap: "5px", */}
{/* padding: "6px 15px 6px 10px", */}
{/* borderRadius: "5px", */}
{/* backgroundColor: "#252525", */}
{/* }} */}
{/* > */}
{/* <RankTrophy style={{ fontSize: "1rem" }} /> */}
{/* <span> Leaderboard </span> */}
{/* </SearchDifficulty> */}
{/* </RouteLink> */}
</SearchContainer>

<CTFHeader>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Common/ImageUpload/useUploadImages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ const useUploadImages = ({
requiredImageWidth,
initImages = [],
requiredImageHeight = 0,
user,
}) => {
const [images, setImages] = useState([]);
const [imagesName, setImagesName] = useState(initImages || []);
const [workerAction, setWorkerAction] = useState(null);

useEffect(() => {
const imageUploadWorker = new Worker("/src/utils/workers/imageUploadWorker.js");
imageUploadWorker.onmessage = (event) => {
Expand Down Expand Up @@ -133,7 +135,7 @@ const useUploadImages = ({
const handleSubmit = async (file) => {
const formData = new FormData();
formData.append("image", file);
await uploadImages(formData);
await uploadImages(formData, user.token);
};

const handleSubmitManyImages = async (files) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dashboard/FormData/FormData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getApiUrl } from "src/features/apiUrl";
const FormData = () => {
const { user } = useSelector((state) => state.auth);

if (!user || user.role !== "admin" || user.role === "team") {
if (!user || user.role !== "admin" || user.role !== "team") {
return <NotFound />;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Dashboard/FormData/InternshipResponse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

const InternshipResponse = () => {
const { user } = useSelector((state) => state.auth);
if (!user || user.role !== "admin" || user.role === "team") {
if (!user || user.role !== "admin" || user.role !== "team") {
return <NotFound />;
}

Expand Down
4 changes: 4 additions & 0 deletions src/components/Dashboard/Notetaker/NoteApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const NoteApp = () => {
dispatch(pinNote({ id: noteId, noteData }));
};

if (isNoteLoading) {
return "loading";
}

return (
<NotesContainer>
<CategorySidebar
Expand Down
6 changes: 5 additions & 1 deletion src/components/Dashboard/Notetaker/NoteDescription.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FaSave } from "react-icons/fa";
import { TbEditCircle } from "react-icons/tb";
import { AiTwotoneDelete } from "react-icons/ai";
import { RiMore2Fill } from "react-icons/ri";
import DOMPurify from "dompurify";

const NoteDescription = ({
children,
Expand Down Expand Up @@ -94,6 +95,9 @@ const NoteDescription = ({
onChangePickedNote(newNote);
handleClose();
};

const purifiedCode = DOMPurify.sanitize(showNote.content);

return (
<NotesDescriptionContainer>
<NotesDescriptionHeader>
Expand Down Expand Up @@ -153,7 +157,7 @@ const NoteDescription = ({
pageName="notes"
/>
) : (
<MarkdownEditor content={showNote.content || ""} previewModeOnly pageName="notes" />
<MarkdownEditor content={purifiedCode || ""} previewModeOnly pageName="notes" />
)}
</div>
</NotesDescription>
Expand Down
20 changes: 9 additions & 11 deletions src/components/Dashboard/Profile/UserLinks/UserLinks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import {
} from "src/components/Dashboard/Profile/UserSocialLinks/UserSocialLinksElements";
import { FaGithub, FaInstagram, FaLinkedin, FaMedium, FaTwitter } from "react-icons/fa";
import { CgWebsite } from "react-icons/cg";
import ConnectionsAndFollows from "src/components/Dashboard/Profile/ConnectionsAndFollows/ConnectionsAndFollows.jsx";
// import ConnectionsAndFollows from "src/components/Dashboard/Profile/ConnectionsAndFollows/ConnectionsAndFollows";
// import ExternalLinkPopUp from "src/components/Common/ExternalLink/ExternalLink.jsx";

const UserLinks = ({
userDetail,
// , isUserDetailsLoading, setShowAuthPopup
}) => {
const UserLinks = ({ userDetail, isUserDetailsLoading, setShowAuthPopup }) => {
const socialUsernames = userDetail?.socialLinks?.map(
(item) => item?.profileUsername !== "" && item?.profileUsername,
);
Expand All @@ -25,13 +23,13 @@ const UserLinks = ({
<UserLinksContainer>
<UserInfo>{userDetail}</UserInfo>

{/* {userDetail?.user && ( */}
{/* <ConnectionsAndFollows */}
{/* isUserDetailsLoading={isUserDetailsLoading} */}
{/* userDetail={userDetail} */}
{/* setShowAuthPopup={setShowAuthPopup} */}
{/* /> */}
{/* )} */}
{userDetail?.user && (
<ConnectionsAndFollows
isUserDetailsLoading={isUserDetailsLoading}
userDetail={userDetail}
setShowAuthPopup={setShowAuthPopup}
/>
)}

{userDetail?.bio?.length === 0 || !userDetail?.bio ? null : (
<UserBio>
Expand Down
7 changes: 6 additions & 1 deletion src/components/Feeds/FeedPage/FeedComments/ReplyCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ const ReplyCard = ({ reply, user, comments, likes, bookmarks, views, displayAt,
<PostHeaderImg src={avatar} alt={reply?.username + `avatar`} />
</LeftSection>
{editMode ? (
<ModifyFeed showPostTags={true} editFeed={reply} onModifyFeed={handleSaveEditedFeed} />
<ModifyFeed
showPostTags={true}
editFeed={reply}
onModifyFeed={handleSaveEditedFeed}
token={user?.token}
/>
) : (
<RightSection>
{/* <RouteLink to={`/feeds/${reply?._id}`}> */}
Expand Down
Loading

0 comments on commit 01a4694

Please sign in to comment.