Skip to content

Commit 8f0dfd6

Browse files
committed
πŸ™οΈπŸ“• ↝ Method to create a 'repository' or a 'node' on the staging
1 parent 05dbaab commit 8f0dfd6

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed

β€Žcomponents/Content/CreateRepo.tsx

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React, { useState, useEffect } from "react";
2+
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
3+
4+
export default function CreateNode() {
5+
const supabase = useSupabaseClient();
6+
const session = useSession();
7+
8+
const [repoName, setNodeName] = useState('');
9+
10+
const createNodeDb = async () => {
11+
try {
12+
if (repoName == '') {
13+
return;
14+
};
15+
16+
const { error, data } = await supabase
17+
.from("posts_old")
18+
.insert({
19+
content: repoName,
20+
author: session?.user?.id,
21+
});
22+
23+
if (error) {
24+
console.error("Error inserting data into Supabase, ", error.message);
25+
return;
26+
};
27+
28+
console.log("Data inserted successfully: ", data);
29+
setNodeName('');
30+
} catch (error) {
31+
console.error("Error creating node: ", error);
32+
};
33+
};
34+
35+
return (
36+
<div>
37+
<input
38+
type="text"
39+
className="border border-gray-300 rounded-md px-3 py-2 mr-2 focus:outline-none focus:border-blue-500"
40+
placeholder="Enter repository name"
41+
value={repoName}
42+
onChange={(e) => setNodeName(e.target.value)}
43+
/>
44+
<button
45+
className="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded"
46+
onClick={createNodeDb}
47+
>
48+
Create Node
49+
</button>
50+
</div>
51+
);
52+
};

β€Žcomponents/Content/FileUpload.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function FileUpload() {
2525
if (error) {
2626
console.error("Error inserting data into Supabase:", error.message);
2727
return;
28-
}
28+
};
2929

3030
console.log("Data inserted successfully:", data);
3131

β€Žpages/index.tsx

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
22
import React, { useEffect, useState } from "react";
3-
import CoreLayout from "../components/Core/Layout";
43
import Layout from "../components/Section/Layout";
54
import { useRouter } from "next/router";
6-
import Login from "./login";
7-
8-
import styles from '../styles/Landing.module.css';
95
import { Metadata } from "next";
106
import FileUpload from "../components/Content/FileUpload";
7+
import CreateNode from "../components/Content/CreateRepo";
118

129
export const metadata: Metadata = {
13-
title: "Star Sailors"
10+
title: "Star Sailors",
1411
}
1512

1613
export default function Home() {
@@ -20,7 +17,7 @@ export default function Home() {
2017

2118
async function logoutUser () {
2219
const { error } = await supabase.auth.signOut()
23-
}
20+
};
2421

2522
const userId = session?.user?.id;
2623

@@ -29,16 +26,17 @@ export default function Home() {
2926
<Layout>
3027
{/* {userId} */}
3128
<div className="flex flex-col gap-4">
29+
<CreateNode />
3230
<FileUpload />
3331
</div>
3432
</Layout>
3533
// <CoreLayout>
36-
)
37-
}
34+
);
35+
};
3836

3937
return (
4038
<div className="grid grid-cols-2 h-screen-navbar">
4139

4240
</div>
4341
);
44-
}
42+
};

0 commit comments

Comments
Β (0)