Skip to content

Commit

Permalink
feat: add filter for first time orgs
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Mittal <[email protected]>
  • Loading branch information
nishantwrp committed Feb 25, 2023
1 parent a911678 commit a996b26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/components/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ const Sidebar = ({ config, showFilters }) => {
</div>
<Divider className="sidebar-divider" />
<div className="sidebar-content-filters">
<Filter
name="shortcuts"
choices={[{ name: "First-time organizations", frequency: 20 }]}
sortBy="frequency"
/>
<Filter name="years" choices={years} sortBy="name" order="desc" />
<Filter name="categories" choices={categories} sortBy="name" />
<Filter
Expand Down
15 changes: 14 additions & 1 deletion src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const getFilteredOrganizations = (organizations, searchQuery, filters) => {
}

// NOTE: YEARS - intersection, REST - union.
const { years, categories, technologies, topics } = filters
const { years, categories, technologies, topics, shortcuts } = filters

if (years.length > 0) {
let newFilteredOrganizations = []
Expand Down Expand Up @@ -109,6 +109,18 @@ const getFilteredOrganizations = (organizations, searchQuery, filters) => {
filteredOrganizations = newFilteredOrganizations
}

if (shortcuts.length > 0) {
// There is only one shortcut. Directly implement it. Need to refactor this.
let newFilteredOrganizations = []
for (const organization of filteredOrganizations) {
const orgYears = Object.keys(organization.years)
if (orgYears.length == 1 && orgYears[0] == 2023) {
newFilteredOrganizations.push(organization)
}
}
filteredOrganizations = newFilteredOrganizations
}

return filteredOrganizations
}

Expand Down Expand Up @@ -136,6 +148,7 @@ const IndexPage = ({ data }) => {
categories: [],
technologies: [],
topics: [],
shortcuts: [],
}

dispatch(
Expand Down
11 changes: 10 additions & 1 deletion src/store/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const filtersSlice = createSlice({
categories: [],
technologies: [],
topics: [],
shortcuts: [],
}
)
},
Expand All @@ -40,18 +41,26 @@ const filtersSlice = createSlice({
updateFiltersInUrl(state)
},
setFilters: (state, action) => {
const { years, categories, technologies, topics } = action.payload
const {
years,
categories,
technologies,
topics,
shortcuts,
} = action.payload
state.years = years
state.categories = categories
state.technologies = technologies
state.topics = topics
state.shortcuts = shortcuts
updateFiltersInUrl(state)
},
clearFilters: state => {
state.years = []
state.categories = []
state.technologies = []
state.topics = []
state.shortcuts = []
updateFiltersInUrl(state)
},
},
Expand Down

0 comments on commit a996b26

Please sign in to comment.