Skip to content

Commit 360faa9

Browse files
authored
Merge pull request #41 from Code-the-Dream-School/share-project-feature
Share project feature
2 parents 803db2b + 0804519 commit 360faa9

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

src/views/HomePage.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const HomePage = () => {
1010
const navigate = useNavigate();
1111

1212
const handleAuthentificationCheck = () => {
13-
console.log("token: ", storedAuth);
1413
if (!storedAuth) {
1514
toaster.create({
1615
title: "Sign In Required!",

src/views/ShareAProject.jsx

+35-36
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,46 @@ import { Checkbox } from "../components/ui/checkbox";
1212
import { Toaster, toaster } from "../components/ui/toaster";
1313

1414
const ShareAProject = () => {
15+
const token = JSON.parse(localStorage.getItem("auth"));
1516
const [newProject, setNewProject] = useState({
16-
title: "",
17-
githubURL: "",
17+
name: "",
1818
description: "",
19-
frameworks: [],
20-
liveDemoURL: "",
21-
comments: "",
22-
date: "",
19+
github_link: "",
20+
youtube_video_link: "",
21+
tags: [],
2322
});
2423

2524
const handleSubmit = async (e) => {
2625
e.preventDefault();
26+
2727
try {
28-
const response = await fetch("http://localhost:8001/addproject", {
28+
const response = await fetch("http://localhost:8001/api/v1/addProject", {
2929
method: "POST",
3030
headers: {
3131
"Content-Type": "application/json",
32+
Authorization: `Bearer ${token}`, // Include the token in the Authorization header
3233
},
33-
body: JSON.stringify({
34-
...newProject,
35-
date: new Date().toISOString(),
36-
}),
34+
body: JSON.stringify(newProject),
3735
});
38-
console.log(newProject);
3936
if (response.ok) {
4037
toaster.create({
4138
title: "Project submitted succesfully!",
4239
type: "success",
43-
duration: 4000,
40+
duration: 8000,
4441
action: {
4542
label: "x",
4643
},
4744
});
4845
setNewProject({
49-
title: "",
50-
githubURL: "",
46+
name: "",
5147
description: "",
52-
frameworks: [],
53-
liveDemoURL: "",
54-
comments: "",
55-
date: "",
48+
github_link: "",
49+
youtube_video_link: "",
50+
tags: [],
5651
});
5752
} else {
58-
console.error("Failed to submit project");
53+
console.error("Failed to add project:", response.statusText);
54+
//console.error("Failed to submit project");
5955
}
6056
} catch (error) {
6157
toaster.create({
@@ -72,9 +68,9 @@ const ShareAProject = () => {
7268
const handleCheckboxChange = (value) => {
7369
setNewProject((prev) => ({
7470
...prev,
75-
frameworks: prev.frameworks.includes(value)
76-
? prev.frameworks.filter((framework) => framework !== value)
77-
: [...prev.frameworks, value],
71+
tags: prev.tags.includes(value)
72+
? prev.tags.filter((tags) => tags !== value)
73+
: [...prev.tags, value],
7874
}));
7975
};
8076

@@ -116,9 +112,9 @@ const ShareAProject = () => {
116112
backgroundColor="rgba(255, 255, 255, 0.16)"
117113
placeholder="Enter your Project"
118114
borderRadius="8px"
119-
value={newProject.title}
115+
value={newProject.name}
120116
onChange={(e) =>
121-
setNewProject({ ...newProject, title: e.target.value })
117+
setNewProject({ ...newProject, name: e.target.value })
122118
}
123119
/>
124120
</Field>
@@ -145,8 +141,8 @@ const ShareAProject = () => {
145141
</Field>
146142
<Fieldset.Root>
147143
<CheckboxGroup
148-
key={newProject.frameworks.length}
149-
defaultValue={newProject.frameworks}
144+
key={newProject.tags.length}
145+
defaultValue={newProject.tags}
150146
name="framework"
151147
>
152148
<Fieldset.Legend
@@ -163,7 +159,7 @@ const ShareAProject = () => {
163159
value="React"
164160
colorPalette="cyan"
165161
variant="solid"
166-
checked={newProject.frameworks.includes("React")}
162+
checked={newProject.tags.includes("React")}
167163
onChange={() => handleCheckboxChange("React")}
168164
>
169165
<span
@@ -180,7 +176,7 @@ const ShareAProject = () => {
180176
value="Node.js"
181177
colorPalette="green"
182178
variant="solid"
183-
checked={newProject.frameworks.includes("Node.js")}
179+
checked={newProject.tags.includes("Node.js")}
184180
onChange={() => handleCheckboxChange("Node.js")}
185181
>
186182
<span
@@ -197,7 +193,7 @@ const ShareAProject = () => {
197193
value="HTML / CSS"
198194
colorPalette="purple"
199195
variant="solid"
200-
checked={newProject.frameworks.includes("HTML / CSS")}
196+
checked={newProject.tags.includes("HTML / CSS")}
201197
onChange={() => handleCheckboxChange("HTML / CSS")}
202198
>
203199
<span
@@ -228,9 +224,9 @@ const ShareAProject = () => {
228224
backgroundColor="rgba(255, 255, 255, 0.16)"
229225
placeholder="Enter your Github repository URL"
230226
borderRadius="8px"
231-
value={newProject.githubURL}
227+
value={newProject.github_link}
232228
onChange={(e) =>
233-
setNewProject({ ...newProject, githubURL: e.target.value })
229+
setNewProject({ ...newProject, github_link: e.target.value })
234230
}
235231
/>
236232
</Field>
@@ -248,9 +244,12 @@ const ShareAProject = () => {
248244
backgroundColor="rgba(255, 255, 255, 0.16)"
249245
placeholder="Enter your Live Demo URL (Optional)"
250246
borderRadius="8px"
251-
value={newProject.liveDemoURL}
247+
value={newProject.youtube_video_link}
252248
onChange={(e) =>
253-
setNewProject({ ...newProject, liveDemoURL: e.target.value })
249+
setNewProject({
250+
...newProject,
251+
youtube_video_link: e.target.value,
252+
})
254253
}
255254
/>
256255
</Field>
@@ -269,10 +268,10 @@ const ShareAProject = () => {
269268
placeholder="Do you have any comments? (Optional)"
270269
borderRadius="8px"
271270
border="2px solid white"
272-
value={newProject.comments}
271+
/*value={newProject.comments}
273272
onChange={(e) =>
274273
setNewProject({ ...newProject, comments: e.target.value })
275-
}
274+
}*/
276275
/>
277276
<Button className="sp-button" variant="solid" type="submit">
278277
SUBMIT PROJECT

0 commit comments

Comments
 (0)