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

chore: added a minor fix to [username] page #1

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
126 changes: 83 additions & 43 deletions src/app/(pages)/[username]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,110 @@
"use client";
import React, { useEffect, useState } from "react";
import PortfolioAbout from "../../../components/portfolio/PortfolioAbout";
import SkillsSection from "@/components/portfolio/PortfolioSkills";
import PortfolioProjectCard from "@/components/portfolio/PortfolioProjectCard";
import { toast } from "sonner";
import Portfolio from "@/Models/portfolioModel";
import { redirect } from "next/navigation";
import { dbConnect } from "@/lib/dbConnect";
import mongoose from "mongoose";

const Page = ({ params }: {
const Page = async ({ params }: {
params: { username: string };
}) => {
const [portfolioData, setPortfolioData] = useState<any>();
const [isLoading, setIsLoading] = useState(true);

const fetchPortfolio = async () => {
try {
const response = await fetch("/api/portfolio/" + params?.username, {
method: "GET",
cache: "no-store",
});
await dbConnect();

const data = await response.json();
const findPortfolio = await Portfolio.findOne({ domain: params.username });

if (response.ok && data.success) {
setPortfolioData(data.data);
setIsLoading(false);
} else {
toast.error(data.message);
}
} catch (error) {
console.log("error on fetching the user ", error);
} finally {
setIsLoading(false);
}
};
if (!findPortfolio) {
redirect('/')
}

if (!findPortfolio?.userid || !mongoose.Types.ObjectId.isValid(findPortfolio?.userid)) {
redirect('/')
}

const userIdObject = new mongoose.Types.ObjectId(findPortfolio?.userid);

const aggregatePipeline = [
{
$match: {
userid: userIdObject,
},
},
{
$lookup: {
from: "abouts",
localField: "userid",
foreignField: "userid",
as: "about",
},
},
{
$lookup: {
from: "links",
localField: "userid",
foreignField: "userid",
as: "links",
},
},
{
$lookup: {
from: "skills",
localField: "userid",
foreignField: "userid",
as: "skills",
},
},
{
$lookup: {
from: "projects",
localField: "userid",
foreignField: "userid",
as: "projects",
},
},
{
$project: {
_id: 1,
about: 1,
links: 1,
skills: 1,
projects: 1,
},
},
];

useEffect(() => {
fetchPortfolio();
}, []);
const portfolioData: any = await Portfolio.aggregate(aggregatePipeline);

console.log(portfolioData)

if (!portfolioData) {
redirect('/')
}

return (
<section className="scroll-smooth!" style={{scrollBehavior: "smooth"}}>
{isLoading ? (
<div className="flex justify-center items-center w-full h-screen">
<span className="loader2"></span>
</div>
) : (
<section className="scroll-smooth!" style={{ scrollBehavior: "smooth" }}>
{
portfolioData && (
<section className="flex scroll-smooth flex-col gap-10 py-2 px-2">
{
portfolioData?.about && portfolioData?.about.length > 0 ? <PortfolioAbout
aboutDatas={portfolioData?.about}
allLinks={portfolioData?.links}
/> : null
portfolioData[0]?.about && portfolioData[0]?.about.length > 0 ? <PortfolioAbout
aboutDatas={portfolioData[0]?.about}
allLinks={portfolioData[0]?.links}
/> : null
}
{
portfolioData?.skills && portfolioData?.skills.length > 0 ? <SkillsSection skillData={portfolioData?.skills} /> : null
portfolioData[0]?.skills && portfolioData[0]?.skills.length > 0 ? <SkillsSection skillData={portfolioData[0]?.skills} /> : null
}
{
portfolioData?.projects && portfolioData?.projects.length > 0 ? <PortfolioProjectCard
projectData={portfolioData?.projects}
/> : null
portfolioData[0]?.projects && portfolioData[0]?.projects.length > 0 ? <PortfolioProjectCard
projectData={portfolioData[0]?.projects}
/> : null
}
{/* <PortfolioContact/>
<SingleShare/> */}
</section>
)
)}
}
</section>
);
};
Expand Down
6 changes: 1 addition & 5 deletions src/components/portfolio/SharePortfolio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ import {
FacebookShareButton,
WhatsappShareButton,
TelegramShareButton,
PinterestShareButton,
TwitterShareButton,
LinkedinShareButton,
MailruShareButton,
EmailShareButton,
FacebookIcon,
EmailIcon,
WhatsappIcon,
TelegramIcon,
PinterestIcon,
TwitterIcon,
LinkedinIcon,
MailruIcon,
} from "react-share";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";

function SharePortfolio() {
const [shareData, setShareData] = React.useState(window.location.href || ""); // Set your share data here
const [shareData, setShareData] = React.useState(window.location.href || "");

useEffect(() => {
setShareData(window.location.href || "");
Expand Down