Skip to content

Commit ac5a6cb

Browse files
committed
Added fetch function to modify papers page as well as created sliver component
1 parent a3bdd0d commit ac5a6cb

File tree

4 files changed

+130
-9
lines changed

4 files changed

+130
-9
lines changed

web/src/components/nav-bar/search-bar.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ import { ChangeEvent, useState } from "react";
22
import { HiSearch } from "react-icons/hi";
33
import "../../App.css";
44

5-
type SearchBarProps = {
5+
interface SearchBarProps {
6+
onSearch: (value: string) => void // Callback to send out search value
67
className?: string;
78
};
89

9-
export default function SearchBar({ className }: SearchBarProps) {
10+
export default function SearchBar({ className, onSearch }: SearchBarProps) {
1011
const [query, setQuery] = useState<string>("");
1112

1213
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
1314
setQuery(e.target.value);
15+
console.log(query)
1416
};
1517

1618
const handleSearch = () => {
17-
console.log(`Searching for: ${query}`);
18-
// Need to implement search function
19+
onSearch(query);
1920
};
2021

2122
const handleKeyPress = (e: any) => {
@@ -34,13 +35,13 @@ export default function SearchBar({ className }: SearchBarProps) {
3435
value={query}
3536
onChange={handleInputChange}
3637
onKeyDown={handleKeyPress}
37-
className="py-1 rounded-lg bg-[#D9D9D9] placeholder-[#909090] h-8 pl-3 w-full"
38+
className="py-1 rounded-lg bg-[#D9D9D9] focus:outline-none placeholder-[#909090] h-8 pl-3 w-full"
3839
/>
3940
<button
4041
onClick={handleSearch}
4142
className="bg-usask-green rounded-lg h-8 p-1"
4243
>
43-
<HiSearch size={24} color="#CDCDCD" />
44+
<HiSearch size={24} className="text-[#CDCDCD]" />
4445
</button>
4546
</div>
4647
);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import "../App.css";
2+
import { TempPaperData } from "../pages/ModifyPage";
3+
import { PaperData } from "../types/types";
4+
5+
// TempPaperData is for testing only
6+
type PaperSliverProp = {
7+
paper: TempPaperData;
8+
index: number;
9+
};
10+
11+
export default function PaperSliver({ paper, index }: PaperSliverProp) {
12+
return (
13+
<div
14+
className={`${
15+
index % 2 ? "bg-[#DADADA]" : "bg-[#EEEEEE]"
16+
} grid grid-cols-6 justify-between p-[3%]`}
17+
>
18+
<div className="col-span-1">
19+
<div className="text-md">{paper.id}.</div>
20+
</div>
21+
<div className="col-span-3">
22+
<div className="text-left text-lg">{paper.paper_name}</div>
23+
<div className="text-xs text-left">{paper.author}</div>
24+
</div>
25+
<div className="col-span-2 flex items-center justify-center">
26+
<button className="bg-usask-green text-[#DADADA]">
27+
Modify Entry
28+
</button>
29+
</div>
30+
</div>
31+
);
32+
}

web/src/pages/ModifyPage.tsx

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,85 @@
11
import "../App.css";
22
import { Card } from "@nextui-org/react";
33
import SearchBar from "../components/nav-bar/search-bar";
4+
import { useEffect, useState } from "react";
5+
import { PaperData } from "../types/types";
6+
import PaperSliver from "../components/paper-sliver";
7+
8+
// For testing only. All instances of 'TempPaperData' will be replaced with 'PaperData'
9+
export type TempPaperData = {
10+
id: number;
11+
paper_name: string;
12+
author: string[];
13+
};
414

515
export default function ModifyPage() {
16+
const [papers, setPapers] = useState<TempPaperData[]>([
17+
{
18+
id: 1,
19+
paper_name:
20+
"SEE In-Flight Data for two Static 32KB Memories on High Earth Orbit",
21+
author: [
22+
"S. Duzellier",
23+
"S. Bourdarie",
24+
"R. Velazco",
25+
"B. Nicolescu",
26+
"R. Ecoffet",
27+
],
28+
},
29+
]);
30+
31+
const fetchPapers = async (search: string) => {
32+
const token = localStorage.getItem("jwtToken");
33+
34+
try {
35+
const response = await fetch(
36+
"https://starr-lab-server.usask.ca/api/adminRequest/getFullPapers",
37+
{
38+
method: "POST",
39+
headers: {
40+
"Content-Type": "application/json",
41+
Authorization: `Bearer ${token}`,
42+
},
43+
body: JSON.stringify({ search }),
44+
}
45+
);
46+
if (response.ok) {
47+
const result = await response.json();
48+
setPapers(result as PaperData[]);
49+
} else {
50+
console.error(`Failed to fetch papers: ${response.status}`);
51+
}
52+
} catch (error) {
53+
console.error(`Error fetching papers: ${error}`);
54+
throw error;
55+
}
56+
};
57+
58+
// Fetch papers when the page first loads (with an empty search)
59+
useEffect(() => {
60+
fetchPapers("");
61+
}, []);
62+
63+
// This is setup to only fetch papers when the search button is clicked,
64+
// we could make it auto update easily instead tho
65+
const handleSearch = (value: string) => {
66+
//console.log(`Search value: ${value}`);
67+
fetchPapers(value);
68+
};
69+
670
return (
771
<div className="flex flex-col items-center justify-center">
872
<div className="bg-[#F4F4F4] w-[70%]">
9-
<div className="py-[4%] text-4xl">Modify Paper Data</div>
10-
<SearchBar className="pb-4" />
11-
<div className="w-full h-8 bg-[#D4D4D4] drop-shadow-md"></div>
73+
<div>
74+
<div className="py-[4%] text-4xl">Modify Paper Data</div>
75+
<SearchBar className="pb-4" onSearch={handleSearch} />
76+
<div className="w-full h-8 bg-[#D4D4D4] drop-shadow-md"></div>
77+
</div>
78+
<div>
79+
{papers.map((paper: TempPaperData, index: number) => (
80+
<PaperSliver paper={paper} index={index} />
81+
))}
82+
</div>
1283
</div>
1384
</div>
1485
);

web/src/types/types.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export type PaperData = {
2+
id: number;
3+
paper_name: string;
4+
year: number;
5+
author: string[];
6+
part_no: string;
7+
type: string;
8+
manufacturer: string;
9+
testing_location: TestLocation;
10+
testing_type: Testing;
11+
data_type: number;
12+
}
13+
14+
export type TestLocation = "Terrestrial" | "Flight";
15+
16+
// Type to ensure testing types are consistent
17+
export type Testing = "SEE" | "TID" | "DD" | "OTHER";

0 commit comments

Comments
 (0)