diff --git a/src/app/carousel/getGames.jsx b/src/app/carousel/getGames.jsx
deleted file mode 100644
index 1bacdc0..0000000
--- a/src/app/carousel/getGames.jsx
+++ /dev/null
@@ -1,34 +0,0 @@
-
-import createClient from "@/utils/supabase/client";
-
-// export default async function GetGames() {
-// const supabase = createClient();
-// const { data: allGames, error, status} = await supabase
-// .from("games")
-// .select("*, profiles!inner(username)");
-
-// if (error) {
-// console.log("COULDN'T GET GAMES")
-// }
-
-// return ({allGames})
-// };
-
-// pages/api/data.js
-export default async function handler(req, res) {
- try {
- const supabase = createClient();
- const { data: allGames, error, status} = await supabase.from("games").select("*, profiles!inner(username)");
-
- if (error) {
- console.log("COULDN'T GET GAMES")
- }
-
- // Return the data to the client
- res.status(200).json(allGames);
- } catch (error) {
- console.error('Error fetching data:', error);
- res.status(500).json({ error: 'Error fetching data' });
- }
- }
-
\ No newline at end of file
diff --git a/src/app/components/DrawerMenu.jsx b/src/app/components/DrawerMenu.jsx
index 1f74af5..f3f2a1e 100644
--- a/src/app/components/DrawerMenu.jsx
+++ b/src/app/components/DrawerMenu.jsx
@@ -82,7 +82,7 @@ export default function DrawerMenu({user}) {
{user && (
-
+
diff --git a/src/app/components/Navbar.jsx b/src/app/components/Navbar.jsx
index fea32e1..c791982 100644
--- a/src/app/components/Navbar.jsx
+++ b/src/app/components/Navbar.jsx
@@ -121,7 +121,7 @@ export default function Nav({user}) {
src={avatarUrl}
/>
-
+
{
+ try {
+ const { data: allGameData, error, status} = await supabase.from("games").select("*, profiles!inner(username)");
+
+ if (error && status !== 406) {
+ throw error;
+ }
+
+ if (data) {
+ setData(allGameData);
+ }
+ } catch (error) {
+ alert("Error loading games!");
+ console.log(error);
+ }
+ }, [supabase]);
+
+ useEffect(() => {
+ allGames();
+ }, [allGames]);
+
return (
Featured Games
-
+
diff --git a/src/app/user/user-page.jsx b/src/app/user/user-page.jsx
index de84088..b237132 100644
--- a/src/app/user/user-page.jsx
+++ b/src/app/user/user-page.jsx
@@ -32,88 +32,34 @@ import React, { useRef } from 'react';
export default function AccountForm() {
const supabase = createClient();
- const [loading, setLoading] = useState(true);
const [fullname, setFullname] = useState(null);
const [username, setUsername] = useState(null);
const [website, setWebsite] = useState(null);
const [avatarUrl, setAvatarUrl] = useState(null);
const [status, setStatus] = useState(null);
const [error, setError] = useState(null);
- const [nameChanged, setNameChange] = useState(null);
- const [usernameChanged, setUserChange] = useState(null);
- const [avatarChanged, setAvatarChange] = useState(null);
- const [selectedFile, setSelectedFile] = useState(null);
const [user, setUserID] = useState(null);
+ const [createdGames, setCreatedGames] = useState([]);
+ const [reviews, setReviews] = useState([]);
-
- // const { name } = useParams();
- // console.log("PARAMS: ", name)
+ // let search = window.location.search;
+ // let params = new URLSearchParams(search);
+ // const name = params.get('username'); //Get user from url query params
- let search = window.location.search;
- let params = new URLSearchParams(search);
- const name = params.get('user');
- console.log("PARAMS: ", name)
-
- const fileInputRef = useRef(null);
-
- const handleButtonClick = () => {
- fileInputRef.current.click();
- };
-
- const handleFileChange = (event) => {
- const file = event.target.files[0];
- // setAvatarUrl(file);
- setAvatarChange(true)
- setSelectedFile(file);
- // You can do further processing with the selected file here
- };
-
- const disabledVariant = {
- base: {
- bg: "gray.200", // Background color for disabled state
- _hover: {
- bg: "gray.200", // Hover background color for disabled state
- },
- _active: {
- bg: "gray.200", // Active background color for disabled state
- },
- },
- };
-
- const getProfile = useCallback(async () => {
+ async function setUserInformation(userid) {
+ //SET BASIC USER INFORMATION
try {
- setLoading(true);
-
- const {data, error1, status1 } = await supabase
- .from("profiles")
- .select(`id`)
- .eq("username", name)
- .single();
-
- setUserID(data.id);
- console.log(data.id)
-
-
- } catch (error) {
- alert("Error loading user data!");
- console.log(error);
- } //finally {
- // setLoading(false);
- // }
- try {
- console.log("user: ", user)
const { data, error, status } = await supabase
.from("profiles")
.select(`full_name, username, website, avatar`)
- .eq("id", user)
+ .eq("id", userid)
.single();
- if (error && status !== 406) {
- throw error;
- }
+ if (error && status !== 406) {
+ throw error;
+ }
if (data) {
- console.log("GOT HERE@")
setFullname(data.full_name);
setUsername(data.username);
setWebsite(data.website);
@@ -123,41 +69,82 @@ export default function AccountForm() {
alert("Error loading user data!");
console.log(error);
}
- }, [user, supabase]);
- useEffect(() => {
- getProfile();
- }, [user, getProfile]);
+ //SET CREATED GAMES
+ try {
+ const { data, error, status } = await supabase
+ .from("games")
+ .select(`name, type, url_tag, description, created_at`)
+ .eq("owner", userid)
+ .maybeSingle();
- async function getMedia() {
- const { data } = supabase
- .storage
- .from('pfps')
- .getPublicUrl(user.id + "/uploaded-pfp")
+ if (error && status !== 406) {
+ throw error;
+ }
- return data;
- }
+ if (data) {
+ setCreatedGames(data);
+ }
+ } catch (error) {
+ alert("Error loading user data!");
+ console.log(error);
+ }
- function closeSuccess() {
- location.reload();
- }
+ //SET REVIEWS
+ try {
+ const { data, error, status } = await supabase
+ .from("ratings")
+ .select(`game_id, rating, comment, created_at`)
+ .eq("user_id", userid)
+ .maybeSingle();
- function closeError() {
- location.reload();
- }
+ if (error && status !== 406) {
+ throw error;
+ }
- function avatarClicked(url) {
- setAvatarUrl(url);
- if (originalAvatar == url) {
- setAvatarChange(false);
- } else {
- setAvatarChange(true);
+ if (data) {
+ setReviews(data);
+ }
+ } catch (error) {
+ alert("Error loading user data!");
+ console.log(error);
}
}
+ const getProfile = useCallback(async (name) => {
+ if (name != null) {
+ try {
+
+ const {data, error1, status1 } = await supabase
+ .from("profiles")
+ .select(`id`)
+ .eq("username", name)
+ .single();
+
+ if (data) {
+ setUserID(data.id);
+ setUserInformation(data.id)
+ }
+
+ } catch (error) {
+ alert("Error loading user data!");
+ console.log(error);
+ }
+
+ }
+
+ }, [user, supabase]);
+
+ useEffect(() => {
+ let search = window.location.search;
+ let params = new URLSearchParams(search);
+ const name = params.get('username'); //Get user from url query params
+ getProfile(name);
+ }, [user, getProfile]);
+
return (
- {/*
+
@@ -171,174 +158,24 @@ export default function AccountForm() {
object-fit= "cover"
/>
-
{fullname} @ {username}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ Created Games
+
-
-
-
-
-
-
+
@@ -346,77 +183,10 @@ export default function AccountForm() {
- {loading && (
-
-
-
- Website is loading
- )
- }
- {status && (
-
-
-
- Success!
-
- Your account settings have been updated. Please close this alert to reload and apply your changes.
-
-
-
-
- )
- }
- {error && (
-
-
-
- Error!
-
- Error updating the data. {error}
-
-
-
-
- )
- }
- */}
+
+
+
-
-
- //
- //
- // setWebsite(e.target.value)}
- // disabled={loading}
- // />
- //
);
}