Skip to content

Commit 9a6f808

Browse files
committed
🐯🐿️ ↝ uuid for ipfs now successfully being uploaded to supabase (centralised)
1 parent 8ca791d commit 9a6f808

File tree

2 files changed

+58
-18
lines changed

2 files changed

+58
-18
lines changed

components/Content/FileUpload.tsx

+56-17
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,71 @@ export default function FileUpload() {
1212
const [uris, setUris] = useState<string[]>([]);
1313

1414
const { mutateAsync: upload } = useStorageUpload();
15-
const onDrop = useCallback(
16-
async (acceptedFiles: File[]) => {
17-
const _uris = await upload({ data: acceptedFiles });
18-
setUris(_uris);
19-
},
20-
[upload],
21-
);
22-
23-
const { getRootProps, getInputProps } = useDropzone({ onDrop });
2415

25-
const uploadAndAddToSupabase = async (files: File[]) => {
16+
const uploadAndAddToSupabase = useCallback(async (files: File[]) => {
2617
try {
2718
const uris = await upload({ data: files });
28-
setUris(uris);
2919

3020
// Add URIs to Supabase table
31-
for (const uri of uris) {
32-
supabase.from('files')
33-
.insert({
34-
filename: uri
35-
});
21+
const { error, data } = await supabase.from('comments').insert(uris.map(uri => ({ content: uri })));
22+
23+
if (error) {
24+
console.error("Error inserting data into Supabase:", error.message);
25+
return;
3626
}
27+
28+
console.log("Data inserted successfully:", data);
29+
30+
setUris(uris);
3731
} catch (error) {
3832
console.error("Error uploading files and adding to Supabase:", error);
3933
}
40-
};
34+
}, [upload, supabase]);
35+
36+
const onDrop = useCallback(async (acceptedFiles: File[]) => {
37+
await uploadAndAddToSupabase(acceptedFiles);
38+
}, [uploadAndAddToSupabase]);
39+
40+
const { getRootProps, getInputProps } = useDropzone({ onDrop });
41+
42+
/*
43+
function createPost() {
44+
supabase
45+
.from('posts_duplicates')
46+
.insert({
47+
author: session?.user?.id,
48+
content,
49+
media: uploads,
50+
planets2: planetId2,
51+
})
52+
.then(async response => {
53+
if (!response.error) {
54+
// Increment the user's experience locally
55+
setUserExperience(userExperience + 1);
56+
57+
// Update the user's experience in the database
58+
await supabase.from('profiles').update({
59+
experience: userExperience + 1,
60+
}).eq('id', session?.user?.id);
61+
62+
// Add a copy of the planet to the user's inventory
63+
await supabase.from('inventoryPLANETS').insert([
64+
{
65+
planet_id: planetId2,
66+
owner_id: session?.user?.id,
67+
},
68+
]);
69+
70+
alert(`Post ${content} created`);
71+
setContent('');
72+
setUploads([]);
73+
if (onPost) {
74+
onPost();
75+
}
76+
}
77+
});
78+
}
79+
*/
4180

4281
const fetchAndRenderFromSupabase = async () => {
4382
try {

pages/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Login from "./login";
77

88
import styles from '../styles/Landing.module.css';
99
import { Metadata } from "next";
10+
import FileUpload from "../components/Content/FileUpload";
1011

1112
export const metadata: Metadata = {
1213
title: "Star Sailors"
@@ -28,7 +29,7 @@ export default function Home() {
2829
<Layout>
2930
{/* {userId} */}
3031
<div className="flex flex-col gap-4">
31-
32+
<FileUpload />
3233
</div>
3334
</Layout>
3435
// <CoreLayout>

0 commit comments

Comments
 (0)