Skip to content

Commit

Permalink
Profile Page Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
SURAJPATIL6088 committed Jul 28, 2023
1 parent e385b98 commit ab896b7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
11 changes: 11 additions & 0 deletions client/src/context/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<StateContext.Provider
value={{
Expand All @@ -68,6 +78,7 @@ export const StateContextProvider = ({ children }) => {
connect,
createCampaign: publishCampaign,
getCampaigns,
getUserCampaigns,
}}
>
{children}
Expand Down
37 changes: 30 additions & 7 deletions client/src/pages/Profile.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
import React from 'react'
import React, { useState, useEffect } from "react";

function Profile() {
return (
<div>Profile</div>
)
}
import DisplayCampaigns from "../components/DisplayCampaigns"
import { useStateContext } from "../context";

export default Profile;
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(
<DisplayCampaigns
title="All Campaigns"
isLoading= {isLoading}
campaigns = {campaigns}
/>
);
};

export default Profile;

0 comments on commit ab896b7

Please sign in to comment.