-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHackathon.jsx
123 lines (113 loc) · 4.28 KB
/
Hackathon.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import React, { useState } from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Nav from "./Nav";
import Home from "./Home";
import Submissions from "./Submissions";
import SubForm from "./SubForm";
import Description from "./Descriptions";
import Editsubmission from "./Editsubmission"
import Navbar from "./Navbar"
import FavDescription from "./FavDescription";
import FavSubmissions from "./FavSubmissions";
import DiaglogBox from "./DiaglogBox";
function Hackathon() {
const [submissions, setSubmissions] = useState([]);
const [favsubmissions, setFavsubmissions] = useState([]);
const [currentSubmission, setCurrentSubmission] = useState(null);
const [selectedCardId, setSelectedCardId] = useState(null);
const [searchQuery, setSearchQuery] = useState('');
const [sortBy, setSortBy] = useState('newest');
const handleSubmission = (submission) => {
setSubmissions((prevSubmissions) => [...prevSubmissions, submission]);
setCurrentSubmission(submission);
};
const addSubmission = (submission) => {
setSubmissions([...submissions, { id: submissions.length + 1, ...submission }]);
setCurrentSubmission(submission);
};
const updateSubmission = (submission) => {
console.log("update submission")
const index = submissions.findIndex((s) => s.id === submission.id);
if (index >= 0) {
setSubmissions((prevSubmissions) => [...prevSubmissions.slice(0, index), submission, ...prevSubmissions.slice(index + 1),]);
setCurrentSubmission(submission);
}
console.log(submission)
};
const handleFormSubmit = (id, data) => {
const newSubmission = { id, ...data };
setSubmissions([...submissions, newSubmission]);
setSubmissions([...submissions, { id, ...data }]);
setCurrentSubmission(newSubmission);
};
const handleFavSubmissions = (submission) => {
setFavsubmissions([...favsubmissions, { id: favsubmissions.length + 1, ...submission }]);
}
return (
<>
<Router>
<Nav />
<Routes>
<Route
path="/"
element={
<>
<Home />
<Navbar searchQuery={searchQuery} setSearchQuery={setSearchQuery} setSortBy={setSortBy} sortBy={sortBy} />
<Submissions submissions={submissions} favsubmissions={favsubmissions} searchQuery={searchQuery} sortBy={sortBy} />
</>
}
/>
<Route
path="/Submissions"
element={
<>
<Home />
<Navbar searchQuery={searchQuery} setSearchQuery={setSearchQuery} setSortBy={setSortBy} sortBy={sortBy} />
<Submissions submissions={submissions} favsubmissions={favsubmissions} searchQuery={searchQuery} sortBy={sortBy} />
</>
}
/>
<Route
path="/FavSubmissions"
element={
<>
<Home />
<Navbar searchQuery={searchQuery} setSearchQuery={setSearchQuery} setSortBy={setSortBy} sortBy={sortBy} />
<FavSubmissions searchQuery={searchQuery} sortBy={sortBy} favsubmissions={favsubmissions} />
</>
}
/>
<Route
path="/SubForm"
element={<SubForm onSubmit={addSubmission} />}
/>
<Route
path="/Description/:id"
element={
<Description
setSubmissions={setSubmissions} setCurrentSubmission={setCurrentSubmission}
setFavsubmissions={setFavsubmissions}
favsubmissions={favsubmissions}
/>}
/>
<Route
path="/FavDescription/:id"
element={
<FavDescription
setFavsubmissions={setFavsubmissions}
favsubmissions={favsubmissions}
/>}
/>
<Route path="/Editsubmission" element={<Editsubmission
onSubmit={updateSubmission}
updateSubmission={updateSubmission}
/>} />
<Route path="/DiaglogBox" element={<DiaglogBox
/>} />
</Routes>
</Router>
</>
);
}
export default Hackathon;