Skip to content

Commit

Permalink
Merge pull request PotLock#132 from PotLock/fix/pots
Browse files Browse the repository at this point in the history
fix search and display detail data pots
  • Loading branch information
kurodenjiro committed Jan 20, 2024
2 parents 07bfa63 + db3dde2 commit 8545b32
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
55 changes: 47 additions & 8 deletions apps/potlock/widget/Components/ListSection.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ownerId, removeProjectsFromCart, addProjectsToCart, setIsCartModalOpen, tab } = props;
const { ownerId, removeProjectsFromCart, addProjectsToCart, setIsCartModalOpen, tab, nav } = props;
const filterList = [
"Newest to Oldest",
"Oldest to Newest",
Expand Down Expand Up @@ -257,14 +257,50 @@ const searchByWordsPots = (projects, searchTerm) => {
setDisplayProject([]);
setLastNumberOfProject(0);
};
const searchByWordsPot = (projects, searchTerm) => {
let findId = [];
const dataArr = props.items;
let alldata = [];
dataArr.forEach((item) => {
const data = Social.getr(`${item.project_id}/profile`);
alldata.push(data);
if (data) {
if (
data.description.toLowerCase().includes(searchTerm.toLowerCase()) ||
data.name.toLowerCase().includes(searchTerm.toLowerCase())
) {
findId.push(item.project_id);
}
}
});
let projectFilterBySearch = [];
dataArr.forEach((project) => {
const data = Social.getr(`${project.project_id}/profile`);
findId.forEach((id) => {
if (tagSelected.length > 0) {
if (data.category == tagSelected[0]) {
if (project.project_id == id) {
projectFilterBySearch.push(project);
}
}
} else {
if (project.project_id == id) {
projectFilterBySearch.push(project);
}
}
});
});

setTotalProjects(projectFilterBySearch);
setDisplayProject([]);
setLastNumberOfProject(0);
};
const searchByWords = (projects, searchTerm) => {
let findId = [];
const dataArr = props.items;
let alldata = [];
dataArr.forEach((item) => {
const data = Social.getr(`${item.id}/profile`);
console.log("data", data.category);
alldata.push(data);
if (data) {
if (
Expand All @@ -275,7 +311,6 @@ const searchByWords = (projects, searchTerm) => {
}
}
});

let projectFilterBySearch = [];
dataArr.forEach((project) => {
const data = Social.getr(`${project.id}/profile`);
Expand Down Expand Up @@ -413,7 +448,7 @@ const OnBottom = styled.div`

return (
<>
{tab != "pots" && (
{tab != "pots" && tab != "pot" && (
<Container>
<Header>
<Title>Featured projects</Title>
Expand Down Expand Up @@ -446,15 +481,20 @@ return (
)}
<Container>
<Header>
<Title>all projects {totalProjects.length}</Title>
<Title>
all {tab == "pots" ? "pots" : "projects"} {totalProjects.length}
</Title>
{/* Search bar */}
<Widget
src={`${ownerId}/widget/Project.SearchBar`}
props={{
tab: tab,
projectLength: totalProjects.length,
setSearchTerm: (value) => {
tab == "pots"
? searchByWordsPots(totalProjects, value)
: tab == "pot"
? searchByWordsPot(totalProjects, value)
: searchByWords(totalProjects, value);
setSearchTerm(value);
},
Expand All @@ -463,7 +503,7 @@ return (
},
}}
/>
{tab != "pots" && (
{tab != "pots" && tab != "pot" && (
<TagsWrapper>
Tags:
{tagsList.map((tag, key) => (
Expand Down Expand Up @@ -493,10 +533,9 @@ return (
))}
</TagsWrapper>
)}
;
</Header>
<InfiniteScroll
loadMore={tab == "pots" ? loadProjectsPost : loadProjects}
loadMore={tab == "pots" || tab == "pot" ? loadProjectsPost : loadProjects}
hasMore={lastNumberOfProject < totalProjects.length}
>
<ProjectList>{displayProject}</ProjectList>
Expand Down
1 change: 0 additions & 1 deletion apps/potlock/widget/Pots/Projects.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// get projects
const { ownerId, potId, potDetail } = props;

const projects = Near.view(potId, "get_approved_applications", {});

if (!projects) return "Loading...";
Expand Down
21 changes: 9 additions & 12 deletions apps/potlock/widget/Project/SearchBar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { projectLength, handleFilterChange, setSearchTerm } = props;

const filterList = [
"Newest to Oldest",
"Oldest to Newest",
Expand Down Expand Up @@ -57,16 +56,17 @@ const FilterIcon = styled.div`

const FilterMenu = styled.div`
position: absolute;
background: #FFF;
background: #fff;
top: 100%;
right: 0;
padding: 8px;
display: flex;
flex-direction: column;
gap: 8px;
border-radius: 6px;
border: 1px solid rgba(41, 41, 41, 0.36);
box-shadow: 0px 12px 20px -4px rgba(123, 123, 123, 0.32), 0px 4px 8px -3px rgba(123, 123, 123, 0.20), 0px 0px 2px 0px rgba(123, 123, 123, 0.36);
border: 1px solid rgba(41, 41, 41, 0.36);
box-shadow: 0px 12px 20px -4px rgba(123, 123, 123, 0.32),
0px 4px 8px -3px rgba(123, 123, 123, 0.2), 0px 0px 2px 0px rgba(123, 123, 123, 0.36);
`;

const FilterItem = styled.div`
Expand All @@ -76,9 +76,9 @@ const FilterItem = styled.div`
gap: 12px;
white-space: nowrap;
&:hover {
background: #dd3345;
color: #FFF;
border-radius: 6px;
background: #dd3345;
color: #fff;
border-radius: 6px;
}
`;

Expand All @@ -101,13 +101,10 @@ return (
</svg>
</SearchIcon>
<SearchBar
placeholder={`Search (${projectLength}) projects`}
placeholder={`Search (${projectLength}) ${props.tab == "pots" ? "pots" : "projects"}`}
onChange={onSearchChange}
/>
<div
style={{ position: "relative" }}
onClick={() => setOpenFilter(!openFilter)}
>
<div style={{ position: "relative" }} onClick={() => setOpenFilter(!openFilter)}>
<FilterButton>
Sort
<FilterIcon>
Expand Down

0 comments on commit 8545b32

Please sign in to comment.