Skip to content

Commit

Permalink
Merge pull request PotLock#122 from PotLock/feat/sorting-project
Browse files Browse the repository at this point in the history
Hot fix card width and sort filter
  • Loading branch information
kurodenjiro committed Jan 13, 2024
2 parents 7ab7e48 + bdf66e7 commit 7e8613f
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions apps/potlock/widget/Components/ListSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ const donationContractId = "donate.potlock.near";
const [totalProjects, setTotalProjects] = useState(props.items);
const [displayProject, setDisplayProject] = useState([]);
const [lastNumberOfProject, setLastNumberOfProject] = useState(0);
const [filterType, setFilterType] = useState(null);
const [searchTerm, setSearchTerm] = useState(null);

if (!totalProjects) return "loading";

console.log(totalProjects);

const loadProjects = () => {
setLastNumberOfProject(lastNumberOfProject + 9);
setDisplayProject(
Expand Down Expand Up @@ -121,6 +119,9 @@ const sortOldToNew = (projects) => {

useEffect(() => {
const newTotalProjects = [];
for (const project of totalProjects) {
console.log(Social.getr(`${project.id}/profile`));
}
const promises = totalProjects.map((project) => {
return Near.asyncView(donationContractId, "get_donations_for_recipient", {
recipient_id: project.id,
Expand All @@ -129,12 +130,12 @@ useEffect(() => {
newTotalProjects.push({ ...project, total });
});
});
Promise.all(promises).then((allProjects) => {
Promise.all(promises).then(() => {
setTotalProjects(newTotalProjects);
});
}, []);

useEffect(() => {
const handleFilterChange = (filterType) => {
switch (filterType) {
case "Newest to Oldest":
sortNewToOld(totalProjects);
Expand All @@ -149,7 +150,7 @@ useEffect(() => {
sortLowestToHighest(totalProjects);
break;
}
}, [filterType]);
};

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -223,6 +224,14 @@ const Tag = styled.div`
}
`;

const OnBottom = styled.div`
width: 100%;
display: flex;
align-items: center;
justify-content: center;
padding: 20px 0;
`;

return (
<Container>
<Header>
Expand All @@ -232,12 +241,12 @@ return (
<Widget
src={"orasci-contributor.near/widget/Potlock.Home.SearchBar"}
props={{
sortNewToOld: (project) => sortNewToOld(project),
sortOldToNew: (project) => sortOldToNew(project),
projectLength: totalProjects.length,
filterList: filterList,
setFilterType: (filter) => {
setFilterType(filter);
setSearchTerm: (value) => {
setSearchTerm(value);
},
handleFilterChange: (filter) => {
handleFilterChange(filter);
},
}}
/>
Expand All @@ -251,5 +260,6 @@ return (
<InfiniteScroll loadMore={loadProjects} hasMore={lastNumberOfProject < totalProjects.length}>
<ProjectList>{displayProject}</ProjectList>
</InfiniteScroll>
{lastNumberOfProject >= totalProjects.length && <OnBottom>On bottom</OnBottom>}
</Container>
);

0 comments on commit 7e8613f

Please sign in to comment.