Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vt-research-connect-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cscapstone-group3
vt-research-connect-frontend
Commits
f5f201aa
Commit
f5f201aa
authored
7 months ago
by
Johann Ruiz
Browse files
Options
Downloads
Patches
Plain Diff
Adding filtering for openings
parent
b2824145
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#10835
failed
7 months ago
Stage: build
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/OpeningsList.tsx
+6
-3
6 additions, 3 deletions
src/components/OpeningsList.tsx
src/contexts/OpeningsContext.tsx
+37
-3
37 additions, 3 deletions
src/contexts/OpeningsContext.tsx
src/pages/OpeningsPage.tsx
+50
-4
50 additions, 4 deletions
src/pages/OpeningsPage.tsx
with
93 additions
and
10 deletions
src/components/OpeningsList.tsx
+
6
−
3
View file @
f5f201aa
import
{
use
Openings
Context
}
from
"
../
contexts/OpeningsContext
.ts
x
"
;
import
{
Openings
Item
}
from
"
../
types
.ts
"
;
import
OpeningListItem
from
"
./OpeningListItem.tsx
"
;
import
"
./OpeningsList.css
"
export
default
function
OpeningsList
()
{
const
{
openings
}
=
useOpeningsContext
();
interface
OpeningsListProps
{
openings
:
OpeningsItem
[];
}
export
default
function
OpeningsList
(
{
openings
}:
OpeningsListProps
)
{
const
openingsList
=
openings
.
map
((
opening
)
=>
(
<
OpeningListItem
key
=
{
opening
.
id
}
opening
=
{
opening
}
/>
));
...
...
This diff is collapsed.
Click to expand it.
src/contexts/OpeningsContext.tsx
+
37
−
3
View file @
f5f201aa
...
...
@@ -6,18 +6,27 @@ import {NO_TOKEN} from "../utils.ts";
interface
OpeningsContextType
{
openings
:
OpeningsItem
[];
refreshOpenings
:
()
=>
void
;
filteredOpenings
:
OpeningsItem
[];
refreshOpenings
:
(
labName
:
string
)
=>
void
;
sortOpenings
:
(
criteria
:
string
)
=>
void
;
filterOpenings
:
(
labName
:
string
)
=>
void
;
}
const
OpeningsContext
=
createContext
<
OpeningsContextType
>
({
openings
:
[],
filteredOpenings
:
[],
refreshOpenings
:
()
=>
{
},
sortOpenings
:
()
=>
{
},
filterOpenings
:
()
=>
{
}
});
export
const
OpeningsProvider
=
({
children
}:
React
.
PropsWithChildren
)
=>
{
const
{
token
}
=
useUserContext
();
const
[
openings
,
setOpenings
]
=
useState
<
OpeningsItem
[]
>
([]);
const
[
filteredOpenings
,
setFilteredOpenings
]
=
useState
<
OpeningsItem
[]
>
([]);
useEffect
(()
=>
{
if
(
token
===
NO_TOKEN
)
{
...
...
@@ -28,20 +37,45 @@ export const OpeningsProvider = ({children}: React.PropsWithChildren) => {
.
catch
(
console
.
error
)
},
[
token
]);
const
refreshOpenings
=
async
()
=>
{
const
refreshOpenings
=
async
(
labName
:
string
=
""
)
=>
{
if
(
token
===
NO_TOKEN
)
{
return
;
}
try
{
const
updatedOpenings
=
await
fetchOpenings
(
token
);
setOpenings
(
updatedOpenings
);
if
(
labName
)
{
const
filtered
=
updatedOpenings
.
filter
(
Opening
=>
Opening
.
labName
===
labName
);
setFilteredOpenings
(
filtered
);
}
else
{
setFilteredOpenings
(
updatedOpenings
);
}
}
catch
(
error
)
{
console
.
error
(
"
Error refreshing Openings
"
,
error
);
}
}
const
sortOpenings
=
(
criteria
:
string
)
=>
{
let
sortedOpenings
=
[...
filteredOpenings
];
if
(
criteria
===
"
oldest
"
)
{
sortedOpenings
.
sort
((
a
,
b
)
=>
new
Date
(
a
.
createdAt
).
getTime
()
-
new
Date
(
b
.
createdAt
).
getTime
());
}
else
if
(
criteria
===
"
newest
"
)
{
sortedOpenings
.
sort
((
a
,
b
)
=>
new
Date
(
b
.
createdAt
).
getTime
()
-
new
Date
(
a
.
createdAt
).
getTime
());
}
setFilteredOpenings
(
sortedOpenings
);
};
const
filterOpenings
=
(
labName
:
string
)
=>
{
if
(
labName
===
""
)
{
setFilteredOpenings
(
openings
);
}
else
{
const
filtered
=
openings
.
filter
(
opening
=>
opening
.
labName
===
labName
);
setFilteredOpenings
(
filtered
);
}
};
return
(
<
OpeningsContext
.
Provider
value
=
{
{
openings
,
refresh
Openings
}
}
>
<
OpeningsContext
.
Provider
value
=
{
{
openings
,
filteredOpenings
,
refreshOpenings
,
sortOpenings
,
filter
Openings
}
}
>
{
children
}
</
OpeningsContext
.
Provider
>
);
...
...
This diff is collapsed.
Click to expand it.
src/pages/OpeningsPage.tsx
+
50
−
4
View file @
f5f201aa
import
'
./OpeningsPage.css
'
import
{
openingsAPI
,
PROFESSOR_ROLE
}
from
"
../utils.ts
"
;
import
{
useState
}
from
"
react
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useUserContext
}
from
"
../contexts/UserContext.tsx
"
;
import
axios
from
"
axios
"
;
import
OpeningsPopupForm
from
"
../components/OpeningsPopupForm.tsx
"
;
import
OpeningsList
from
"
../components/OpeningsList.tsx
"
;
import
{
useOpeningsContext
}
from
"
../contexts/OpeningsContext.tsx
"
;
import
{
ProfessorUser
}
from
"
../types.ts
"
;
import
{
useResearchLabContext
}
from
'
../contexts/ResearchLabContext.tsx
'
;
export
default
function
OpeningsPage
()
{
const
{
refreshOpenings
}
=
useOpeningsContext
();
const
{
openings
,
filterOpenings
,
refreshOpenings
,
sortOpenings
,
filteredOpenings
}
=
useOpeningsContext
();
const
[
showPopup
,
setShowPopup
]
=
useState
(
false
);
const
{
token
,
role
}
=
useUserContext
();
const
{
labs
}
=
useResearchLabContext
();
const
[
currentOpenings
,
setCurrentOpenings
]
=
useState
(
openings
);
const
[
currentLab
,
setCurrentLab
]
=
useState
(
""
);
useEffect
(()
=>
{
setCurrentLab
(
""
);
filterOpenings
(
""
);
},
[]);
useEffect
(()
=>
{
setCurrentOpenings
(
filteredOpenings
);
},
[
filteredOpenings
]);
const
togglePopup
=
()
=>
{
setShowPopup
(
!
showPopup
);
...
...
@@ -36,7 +56,7 @@ export default function OpeningsPage() {
})
.
then
(
response
=>
{
console
.
log
(
'
Opening created successfully:
'
,
response
.
data
);
refreshOpenings
();
refreshOpenings
(
currentLab
);
})
.
catch
(
error
=>
{
console
.
error
(
'
Error creating opening:
'
,
error
);
...
...
@@ -44,11 +64,37 @@ export default function OpeningsPage() {
togglePopup
();
};
const
handleSortChange
=
(
event
:
React
.
ChangeEvent
<
HTMLSelectElement
>
)
=>
{
sortOpenings
(
event
.
target
.
value
);
// Sort openings based on selected criteria
};
const
handleLabChange
=
(
event
:
React
.
ChangeEvent
<
HTMLSelectElement
>
)
=>
{
const
labName
=
event
.
target
.
value
;
setCurrentLab
(
labName
);
filterOpenings
(
labName
);
};
return
(
<
div
className
=
'openings-page center-content'
>
<
section
className
=
'openings-header'
>
<
h1
>
Current Openings
</
h1
>
<
div
className
=
'openings-header-buttons'
>
<
div
className
=
'sort-dropdown'
>
<
label
htmlFor
=
"filter"
className
=
'secondary-button'
>
Sort by:
</
label
>
<
select
className
=
'secondary-button'
name
=
"filter"
id
=
"filter"
onChange
=
{
handleSortChange
}
>
<
option
value
=
"newest"
>
Date (Newest to Oldest)
</
option
>
<
option
value
=
"oldest"
>
Date (Oldest to Newest)
</
option
>
</
select
>
</
div
>
<
div
className
=
'sort-dropdown'
>
<
label
htmlFor
=
"lab"
className
=
'secondary-button'
>
Lab Filter:
</
label
>
<
select
className
=
'secondary-button'
id
=
"lab"
name
=
"lab"
onChange
=
{
handleLabChange
}
>
<
option
value
=
""
>
All labs
</
option
>
{
labs
.
map
((
lab
)
=>
(
<
option
key
=
{
lab
.
id
}
value
=
{
lab
.
name
}
>
{
lab
.
name
}
</
option
>
))
}
</
select
>
</
div
>
{
(
role
===
PROFESSOR_ROLE
)
&&
(
<>
<
button
className
=
'primary-button'
onClick
=
{
togglePopup
}
>
Add Opening
</
button
>
...
...
@@ -58,7 +104,7 @@ export default function OpeningsPage() {
</
div
>
</
section
>
<
OpeningsList
/>
<
OpeningsList
openings
=
{
currentOpenings
}
/>
</
div
>
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment