-
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
base: main
Are you sure you want to change the base?
Changes from all commits
f28f085
8d742ba
77cd7ad
067ab15
72f6cac
1b7f34e
8f0f1ff
8c59ac2
6e480d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: ["2025"], | ||||||||||
| filterMap: { years: [2025], credits: [], hourlyPay: 0, majors: [] }, | ||||||||||
|
Comment on lines
+21
to
+22
|
||||||||||
| activeFilters: ["2025"], | |
| filterMap: { years: [2025], credits: [], hourlyPay: 0, majors: [] }, | |
| activeFilters: [currYr.toString()], | |
| filterMap: { years: [currYr], credits: [], hourlyPay: 0, majors: [] }, |
| 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); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,94 +33,97 @@ export default function SavedPage() { | |
| } catch { | ||
| console.log("Error fetching saved"); | ||
| } | ||
| console.log(saved) | ||
|
||
| } | ||
|
|
||
| useEffect(() => { | ||
| fetchSaved(); | ||
| }, []); | ||
|
Comment on lines
39
to
41
|
||
|
|
||
| return ( | ||
| <section className="center container-xl"> | ||
| <h1 className="text-center my-4 text-4xl font-extrabold leading-none tracking-tight text-gray-900 md:text-5xl lg:text-6xl"> | ||
| Saved Opportunities | ||
| </h1> | ||
| <div className="p-4"> | ||
| <div className="overflow-x-auto"> | ||
| {!saved && "Loading..."} | ||
| {saved && ( | ||
| <table> | ||
| <tr> | ||
| <th>Name</th> | ||
| <th>Description</th> | ||
| <th>Recommended Experience</th> | ||
| <th>Pay</th> | ||
| <th>Credits</th> | ||
| <th>Semester</th> | ||
| <th>Year</th> | ||
| <th>Application Due</th> | ||
| <th>Location</th> | ||
| <th>Unsave</th> | ||
| </tr> | ||
| {saved.map((opportunity) => ( | ||
| <tr key={opportunity.id}> | ||
| <td>{opportunity.name}</td> | ||
| <td>{opportunity.description}</td> | ||
| <td>{opportunity.recommended_experience}</td> | ||
| <td>{opportunity.pay}</td> | ||
| <td>{opportunity.credits}</td> | ||
| <td>{opportunity.semester}</td> | ||
| <td>{opportunity.year}</td> | ||
| <td style={{ | ||
| color: (() => { | ||
| const today = new Date(); | ||
| const dueDate = new Date(opportunity.application_due); | ||
| const oneWeek = 7 * 24 * 60 * 60 * 1000; | ||
| <table className="w-full border-collapse"> | ||
| <thead> | ||
| <tr className="bg-gray-100"> | ||
| <th className="p-3 text-left border">Name</th> | ||
| <th className="p-3 text-left border">Description</th> | ||
| <th className="p-3 text-left border">Recommended Experience</th> | ||
| <th className="p-3 text-left border">Pay</th> | ||
| <th className="p-3 text-left border">Credits</th> | ||
| <th className="p-3 text-left border">Semester</th> | ||
| <th className="p-3 text-left border">Year</th> | ||
| <th className="p-3 text-left border">Application Due</th> | ||
| <th className="p-3 text-left border">Location</th> | ||
| <th className="p-3 text-left border">Unsave</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {saved.map((opportunity) => ( | ||
| <tr key={opportunity.id}> | ||
| <td className="p-3 border font-medium">{opportunity.name}</td> | ||
| <td className="p-3 border">{opportunity.description}</td> | ||
| <td className="p-3 border">{opportunity.recommended_experience}</td> | ||
| <td className="p-3 border">{opportunity.pay}</td> | ||
| <td className="p-3 border">{opportunity.credits}</td> | ||
| <td className="p-3 border">{opportunity.semester}</td> | ||
| <td className="p-3 border">{opportunity.year}</td> | ||
| <td className="p-3 border border-black" style={{ | ||
| color: (() => { | ||
| const today = new Date(); | ||
| const dueDate = new Date(opportunity.application_due); | ||
| const oneWeek = 7 * 24 * 60 * 60 * 1000; | ||
|
|
||
| if (dueDate < today) { | ||
| return "red"; | ||
| } else if (dueDate.getTime() - today.getTime() <= oneWeek) { | ||
| return "orange"; | ||
| } else { | ||
| return "black"; | ||
| } | ||
| })() | ||
| }}> | ||
| {new Date(opportunity.application_due).toLocaleDateString("en-US")} | ||
| </td> | ||
| <td>{opportunity.location}</td> | ||
| <td> | ||
| <button className="p-2 bg-blue-600 text-white font-semibold rounded-lg shadow-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500" | ||
| onClick={async () => { | ||
| try { | ||
| const headers: Record<string, string> = { | ||
| "Content-Type": "application/json", // Good practice for cross-origin requests | ||
| }; | ||
| if (csrfToken) { | ||
| headers["X-CSRF-TOKEN"] = csrfToken; // Include the token only when defined | ||
| } | ||
| if (dueDate < today) { | ||
| return "red"; | ||
| } else if (dueDate.getTime() - today.getTime() <= oneWeek) { | ||
| return "orange"; | ||
| } else { | ||
| return "black"; | ||
| } | ||
| })() | ||
| }}> | ||
| {new Date(opportunity.application_due).toLocaleDateString("en-US")} | ||
| </td> | ||
| <td className="p-3 border">{opportunity.location}</td> | ||
| <td className="p-3 border"> | ||
| <button className="p-2 bg-blue-600 text-white font-semibold rounded-lg shadow-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500" | ||
| onClick={async () => { | ||
| try { | ||
| const headers: Record<string, string> = { | ||
| "Content-Type": "application/json", // Good practice for cross-origin requests | ||
| }; | ||
| if (csrfToken) { | ||
| headers["X-CSRF-TOKEN"] = csrfToken; // Include the token only when defined | ||
| } | ||
|
|
||
| const response = await fetch( | ||
| `${import.meta.env.VITE_BACKEND_SERVER}/unsaveOpportunity/${opportunity.id}`, { | ||
| method: "DELETE", | ||
| credentials: "include", | ||
| headers, | ||
| }); | ||
| const response = await fetch( | ||
| `${import.meta.env.VITE_BACKEND_SERVER}/unsaveOpportunity/${opportunity.id}`, { | ||
| method: "DELETE", | ||
| credentials: "include", | ||
| headers, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error("Failed to unsave"); | ||
| } | ||
| if (!response.ok) { | ||
| throw new Error("Failed to unsave"); | ||
| } | ||
|
|
||
| setSaved(prev => prev ? prev.filter(o => o.id !== opportunity.id) : prev); | ||
| } catch { | ||
| console.log("Error unsaving opportunity"); | ||
| } | ||
| }} | ||
| > | ||
| Unsave | ||
| </button> | ||
| </td> | ||
| </tr> | ||
| ))} | ||
| setSaved(prev => prev ? prev.filter(o => o.id !== opportunity.id) : prev); | ||
| } catch { | ||
| console.log("Error unsaving opportunity"); | ||
| } | ||
| }} | ||
| > | ||
| Unsave | ||
| </button> | ||
| </td> | ||
| </tr> | ||
| ))} | ||
| </tbody> | ||
| </table> | ||
| )} | ||
| </section> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
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.