-
Notifications
You must be signed in to change notification settings - Fork 3
Saved opportunities integration, individual opportunity view, opportunity context rework #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WBroadwell
wants to merge
11
commits into
main
Choose a base branch
from
Will-Frontend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f28f085
modified: src/App.tsx
WBroadwell 8d742ba
modified: src/opportunities/components/OpportunitiesDetails.tsx
WBroadwell 77cd7ad
modified: src/individuals/pages/Saved.tsx
WBroadwell 067ab15
new file: src/context/OpportunityContext.tsx
WBroadwell 72f6cac
modified: src/context/OpportunityContext.tsx
WBroadwell 1b7f34e
new file: docs/posters/labconnect_F25_poster.png
WBroadwell 8f0f1ff
new file: docs/posters/labconnect_F25_poster.pdf
WBroadwell 8c59ac2
Remove console.log
RafaelCenzano 6e480d2
Add semicolon
RafaelCenzano ac623b0
Merge branch 'main' into Will-Frontend
WBroadwell aa3138d
modified: README.md
WBroadwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| // src/context/OpportunityContext.tsx | ||
| import React, { createContext, useReducer, useCallback } from "react"; | ||
| import { OpportunityAction } from "../types/opportunityaction"; | ||
| import { Opportunity } from "../types/opportunity"; | ||
| import { Filters } from "../types/filters"; | ||
|
|
||
| const currYr = new Date().getFullYear(); | ||
|
|
||
| interface OpportunityState { | ||
| filters: { | ||
| activeFilters: string[]; | ||
| filterMap: Filters; | ||
| }; | ||
| query: string; | ||
| activeId: string; | ||
| opportunities: Opportunity[]; | ||
| } | ||
|
|
||
| const initialState: OpportunityState = { | ||
| filters: { | ||
| activeFilters: [currYr.toString()], | ||
| filterMap: { years: [currYr], credits: [], hourlyPay: 0, majors: [] }, | ||
| }, | ||
| query: "", | ||
| activeId: "", | ||
| opportunities: [], | ||
| }; | ||
|
|
||
| export interface OpportunityContextType { | ||
| activeFilters: OpportunityState["filters"]["activeFilters"]; | ||
| filterMap: OpportunityState["filters"]["filterMap"]; | ||
| opportunities: OpportunityState["opportunities"]; | ||
| resetFilters: () => void; | ||
| removeFilter: (name: string) => void; | ||
| setFilters: (activeFilters: string[], filterMap: Filters) => void; | ||
| setQuery: (query: string) => void; | ||
| setOpportunities: (opportunities: Opportunity[]) => void; | ||
| } | ||
|
|
||
| // Stable default values for HMR-safe context | ||
| const noop = () => {}; | ||
|
|
||
| export const OpportunityContext = createContext<OpportunityContextType>({ | ||
| activeFilters: initialState.filters.activeFilters, | ||
| filterMap: initialState.filters.filterMap, | ||
| opportunities: initialState.opportunities, | ||
| resetFilters: noop, | ||
| removeFilter: noop, | ||
| setFilters: noop, | ||
| setQuery: noop, | ||
| setOpportunities: noop, | ||
| }); | ||
|
|
||
| export const OpportunityProvider = ({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) => { | ||
| const [opportunityState, dispatch] = useReducer( | ||
| (state: OpportunityState, action: OpportunityAction) => { | ||
| switch (action.type) { | ||
| case "SET_QUERY": | ||
| return { ...state, query: action.query }; | ||
|
|
||
| case "SET_FILTERS": | ||
| if (!action.activeFilters || !action.filterMap) return state; | ||
| return { | ||
| ...state, | ||
| filters: { | ||
| activeFilters: action.activeFilters, | ||
| filterMap: action.filterMap, | ||
| }, | ||
| }; | ||
|
|
||
| case "RESET_FILTERS": | ||
| return { | ||
| ...state, | ||
| filters: { | ||
| activeFilters: [currYr.toString()], | ||
| filterMap: { | ||
| years: [currYr], | ||
| credits: [], | ||
| hourlyPay: 0, | ||
| majors: [], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| case "REMOVE_FILTER": | ||
| if (!action.filter) return state; | ||
| const newActiveFilters = state.filters.activeFilters.filter( | ||
| (filter) => filter !== action.filter | ||
| ); | ||
| const newFilterMap = { | ||
| ...state.filters.filterMap, | ||
| years: state.filters.filterMap.years.filter( | ||
| (year) => year !== parseInt(action.filter) | ||
| ), | ||
| credits: action.filter.includes("Credit") | ||
| ? [] | ||
| : state.filters.filterMap.credits, | ||
| majors: state.filters.filterMap.majors.filter( | ||
| (major) => major !== action.filter | ||
| ), | ||
| hourlyPay: action.filter.includes("$") | ||
| ? 0 | ||
| : state.filters.filterMap.hourlyPay, | ||
| }; | ||
| return { | ||
| ...state, | ||
| filters: { | ||
| activeFilters: newActiveFilters, | ||
| filterMap: newFilterMap, | ||
| }, | ||
| }; | ||
|
|
||
| case "SET_OPPORTUNITIES": | ||
| if (!action.opportunities) return state; | ||
| return { ...state, opportunities: action.opportunities }; | ||
|
|
||
| default: | ||
| return state; | ||
| } | ||
| }, | ||
| initialState | ||
| ); | ||
|
|
||
| const resetFilters = useCallback( | ||
| () => dispatch({ type: "RESET_FILTERS" }), | ||
| [] | ||
| ); | ||
|
|
||
| const removeFilter = useCallback( | ||
| (name: string) => dispatch({ type: "REMOVE_FILTER", filter: name }), | ||
| [] | ||
| ); | ||
|
|
||
| const setFilters = useCallback( | ||
| (activeFilters: string[], filterMap: Filters) => | ||
| dispatch({ type: "SET_FILTERS", activeFilters, filterMap }), | ||
| [] | ||
| ); | ||
|
|
||
| const setQuery = useCallback( | ||
| (query: string) => dispatch({ type: "SET_QUERY", query }), | ||
| [] | ||
| ); | ||
|
|
||
| const setOpportunities = useCallback( | ||
| (opportunities: Opportunity[]) => | ||
| dispatch({ type: "SET_OPPORTUNITIES", opportunities }), | ||
| [] | ||
| ); | ||
|
|
||
| return ( | ||
| <OpportunityContext.Provider | ||
| value={{ | ||
| activeFilters: opportunityState.filters.activeFilters, | ||
| filterMap: opportunityState.filters.filterMap, | ||
| opportunities: opportunityState.opportunities, | ||
| resetFilters, | ||
| removeFilter, | ||
| setFilters, | ||
| setQuery, | ||
| setOpportunities, | ||
| }} | ||
| > | ||
| {children} | ||
| </OpportunityContext.Provider> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { useContext } from "react"; | ||
| import { OpportunityContext } from "./OpportunityContext"; | ||
|
|
||
| export const useOpportunity = () => { | ||
| return useContext(OpportunityContext); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
queryfield in state is set but never exposed through the context provider. It should be added to theOpportunityContextTypeinterface and the context provider value to be usable by consuming components.