From ab896b7638ec7b9fe701bc289c8273c9b606a98a Mon Sep 17 00:00:00 2001 From: SURAJ BALARAM PATIL <78692972+SURAJPATIL6088@users.noreply.github.com> Date: Fri, 28 Jul 2023 16:39:15 +0530 Subject: [PATCH] Profile Page Updated --- client/src/context/index.jsx | 11 +++++++++++ client/src/pages/Profile.jsx | 37 +++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/client/src/context/index.jsx b/client/src/context/index.jsx index 528f3e7..e5dbf74 100644 --- a/client/src/context/index.jsx +++ b/client/src/context/index.jsx @@ -60,6 +60,16 @@ export const StateContextProvider = ({ children }) => { return parsedCampaigns; }; + const getUserCampaigns = async () => { + const allCampaigns = await getCampaigns(); + + const filteredCampaigns = allCampaigns.filter( + (campaign) => campaign.owner === address + ); + + return filteredCampaigns; + }; + return ( { connect, createCampaign: publishCampaign, getCampaigns, + getUserCampaigns, }} > {children} diff --git a/client/src/pages/Profile.jsx b/client/src/pages/Profile.jsx index 2d729c2..ff3adef 100644 --- a/client/src/pages/Profile.jsx +++ b/client/src/pages/Profile.jsx @@ -1,9 +1,32 @@ -import React from 'react' +import React, { useState, useEffect } from "react"; -function Profile() { - return ( -
Profile
- ) -} +import DisplayCampaigns from "../components/DisplayCampaigns" +import { useStateContext } from "../context"; -export default Profile; \ No newline at end of file +const Profile = () => { + const [isLoading, setIsLoading] = useState(false); + const [campaigns, setCampaigns] = useState([]); + + const { address, contract, getUserCampaigns } = useStateContext(); + + const fetchCampaigns = async() => { + setIsLoading(true); + const data = await getUserCampaigns(); + setCampaigns(data); + setIsLoading(false); + } + + useEffect(() => { + if(contract) fetchCampaigns(); + }, [address, contract]); + + return( + + ); +}; + +export default Profile;