Skip to content

Commit

Permalink
fix Card; fix Donate button issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdas committed May 24, 2024
1 parent 8b8d2c7 commit f771d43
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
1 change: 1 addition & 0 deletions alem.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
}
},
"options": {
"ejectStatefulComponents": false,
"keepRoute": false,
"createLoaderWidget": true,
"loadingComponentFile": "src/components/SuspenseLoading.tsx",
Expand Down
8 changes: 3 additions & 5 deletions src/components/Card/ButtonDonation.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { context, useEffect } from "alem";
import { context } from "alem";
import { useDonationModal } from "@app/hooks/useDonationModal";
import useModals from "@app/hooks/useModals";
import Button from "../Button";

const ButtonDonation = ({ allowDonate, projectId }: { allowDonate: boolean; projectId: string }) => {
const Modals = useModals();
const { setDonationModalProps } = useDonationModal();
useEffect(() => {}, []); // make the component statefull so it does not break

return (
<div
onClick={(e) => e.preventDefault()}
Expand All @@ -15,7 +13,7 @@ const ButtonDonation = ({ allowDonate, projectId }: { allowDonate: boolean; proj
color: "#292929",
}}
>
<Modals />
{/* <Modals /> */}
{allowDonate && context.accountId && (
<Button
varient="tonal"
Expand Down
5 changes: 3 additions & 2 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Big, RouteLink, Social, useEffect } from "alem";
import { Big, RouteLink, Social } from "alem";
import DonateSDK from "@app/SDK/donate";
import PotSDK from "@app/SDK/pot";
import routesPath from "@app/routes/routesPath";
Expand All @@ -8,7 +8,6 @@ import ipfsUrlFromCid from "@app/utils/ipfsUrlFromCid";
import yoctosToNear from "@app/utils/yoctosToNear";
import yoctosToUsdWithFallback from "@app/utils/yoctosToUsdWithFallback";
import CardSkeleton from "../../pages/Projects/components/CardSkeleton";
import Button from "../Button";
import Image from "../mob.near/Image";
import ButtonDonation from "./ButtonDonation";
import {
Expand All @@ -33,6 +32,8 @@ import {
const Card = (props: any) => {
const { payoutDetails, allowDonate: _allowDonate, potId } = props;

// const Modals = useModals();

const projectId = props.project.registrant_id || props.projectId;
const profile = Social.getr(`${projectId}/profile`) as any;
const allowDonate = _allowDonate ?? true;
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Pot/Pot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Big, useParams, useCache, useMemo } from "alem";
import PotSDK from "@app/SDK/pot";
import useModals from "@app/hooks/useModals";
import { PotDetail } from "@app/types";
import Tabs from "../Profile/components/Tabs";
import Header from "./components/Header/Header";
Expand Down Expand Up @@ -50,8 +51,11 @@ const Pot = () => {
return options.find((option: any) => option.id === nav).source;
}, []);

const Modals = useModals();

return (
<Wrapper>
<Modals />
<HeaderStatus />
<Header />

Expand Down
3 changes: 3 additions & 0 deletions src/pages/Projects/components/AllProjects/AllProjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Social, createDebounce, useEffect, useState } from "alem";
import DonateSDK from "@app/SDK/donate";
import Card from "@app/components/Card/Card";
import FilterDropdown from "@app/components/Inputs/FilterDropdown/FilterDropdown";
import useModals from "@app/hooks/useModals";
import getProjects from "@app/services/getProjects";
import { Project } from "@app/types";
import getTagsFromSocialProfileData from "@app/utils/getTagsFromSocialProfileData";
Expand All @@ -14,6 +15,7 @@ import tagsList from "./tagsList";

const AllProjects = () => {
const projectsData = getProjects();
const Modals = useModals();

const [totalDonation, setTotalDonation] = useState(0);
const [totalDonated, setTotalDonated] = useState("0");
Expand Down Expand Up @@ -121,6 +123,7 @@ const AllProjects = () => {

return (
<Container>
<Modals />
<Header>
<Title>
All projects
Expand Down
33 changes: 12 additions & 21 deletions src/pages/Projects/components/FeaturedProjects/FeaturedProjects.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { useEffect, useMemo, useState } from "alem";
import { State } from "alem";
import Card from "@app/components/Card/Card";
import useModals from "@app/hooks/useModals";
import getProjects from "@app/services/getProjects";
import { Project } from "@app/types";
import CardSkeleton from "../CardSkeleton";
import { ContainerHeader, Header, OnBottom, ProjectList, Title } from "./styles";

const FeaturedProjects = () => {
const projectsData = getProjects();
const [projects, setProjects] = useState<Project[]>([]);
State.init({});
const Modals = useModals();

useEffect(() => {
if (projectsData) {
const { featuredProjects } = projectsData;
setProjects(featuredProjects);
}
}, [projectsData]);
const { featuredProjects: projects } = getProjects();

const LoadingCards = () => (
<>
Expand All @@ -24,24 +19,20 @@ const FeaturedProjects = () => {
</>
);

const projectCards = useMemo(
() => (
<>
{projects.map((project: any) => {
return <Card key={project.registrant_id} projectId={project.registrant_id} />;
})}
</>
),
[projects],
);
const projectCards = projects
? projects.map((project: any) => {
return <Card key={project.registrant_id} projectId={project.registrant_id} />;
})
: [];

return (
<ContainerHeader>
<Modals />
<Header>
<Title>Featured projects</Title>
</Header>

<ProjectList>{projects.length === 0 || !projectsData ? <LoadingCards /> : <>{projectCards}</>}</ProjectList>
<ProjectList>{projects.length === 0 || !projects ? <LoadingCards /> : <>{projectCards}</>}</ProjectList>
<OnBottom></OnBottom>
</ContainerHeader>
);
Expand Down

0 comments on commit f771d43

Please sign in to comment.