Skip to content

Commit ab7cae9

Browse files
authored
final fixes (#34)
2 parents 4917d23 + 4a6754b commit ab7cae9

File tree

12 files changed

+343
-125
lines changed

12 files changed

+343
-125
lines changed

β€Žweb/components/RefinementList.jsβ€Ž

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,31 @@ const RefinementList = ({
88
searchForItems,
99
createURL,
1010
}) => (
11-
<ul className="flex justify-center mt-10">
11+
<ul className=" hidden lg:flex lg:justify-center lg:mt-10 lg:mx-10">
1212
<span className="text-white font-bold">Filter By:</span>
13-
{items.map((item) => (
14-
<span key={item.label}>
15-
<a
16-
className="text-xs text-white font-medium font-mono bg-primary-end bg-opacity-50 border-primary-start border-2 rounded-full px-3 py-2 mx-2 hover:bg-opacity-80"
17-
href={createURL(item.value)}
18-
style={{ backgroundColor: item.isRefined ? "#59AF77" : "" }}
19-
onClick={(event) => {
20-
event.preventDefault();
21-
refine(item.value);
22-
}}
23-
>
24-
{isFromSearch ? (
25-
<Highlight attribute="label" hit={item} />
26-
) : (
27-
item.label
28-
)}{" "}
29-
({item.count})
30-
</a>
31-
</span>
32-
))}
13+
{items.map((item, i) => {
14+
if (i < 6)
15+
return (
16+
<span key={item.label}>
17+
<a
18+
className="text-xs text-white font-medium font-mono bg-primary-end bg-opacity-50 border-primary-start border-2 rounded-full px-3 py-2 mx-2 hover:bg-opacity-80"
19+
href={createURL(item.value)}
20+
style={{ backgroundColor: item.isRefined ? "#59AF77" : "" }}
21+
onClick={(event) => {
22+
event.preventDefault();
23+
refine(item.value);
24+
}}
25+
>
26+
{isFromSearch ? (
27+
<Highlight attribute="label" hit={item} />
28+
) : (
29+
item.label
30+
)}{" "}
31+
({item.count})
32+
</a>
33+
</span>
34+
);
35+
})}
3336
</ul>
3437
);
3538

β€Žweb/components/SearchBar.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function SearchBar({ currentRefinement, refine, placeholder = "Search" }) {
88
return (
99
<div className="w-full flex justify-center">
1010
<div className="absolute w-8/12 h-14 flex justify-end items-center ">
11-
<div className="bg-secondary-solid z-20 h-14 w-1/6 rounded-r-lg flex items-center divide-x divide-white">
11+
<div className="bg-secondary-solid z-20 h-14 w-1/6 rounded-r-lg flex items-center divide-x divide-white divide-opacity-40">
1212
<button
1313
onClick={() => router.push("/explore/people")}
1414
className="w-1/2 h-full hover:bg-primary-solid"
@@ -20,7 +20,7 @@ function SearchBar({ currentRefinement, refine, placeholder = "Search" }) {
2020
</button>
2121
<button
2222
onClick={() => router.push("/explore/blog")}
23-
className="w-1/2 h-full hover:bg-primary-solid hover:rounded-r-lg"
23+
className="w-1/2 h-full hover:bg-primary-solid rounded-r-lg"
2424
>
2525
<div className="text-sm">πŸ“°</div>
2626
<div className="text-sm font-mono font-medium text-white">Blog</div>

β€Žweb/lib/utils.jsβ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@ export const truncatePost = (post) => {
44
}
55
return post;
66
};
7+
8+
export const getTimeOfDay = (hour) => {
9+
if (hour >= 5 && hour < 12) {
10+
return "Good Morning πŸŒ₯";
11+
} else if (hour >= 12 && hour < 17) {
12+
return "Good Afternoon 🌞";
13+
} else if (hour >= 17 && hour < 20) {
14+
return "Good Evening πŸŒ‡";
15+
} else {
16+
return "Good Night 🌘";
17+
}
18+
};

β€Žweb/pages/edituser.jsβ€Ž

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import React, { useEffect, useState } from "react";
2+
import { useAuth } from "../lib/auth";
3+
import { getCurrentUser, searchUsers, signOut } from "../lib/connection";
4+
import Image from "next/image";
5+
import { useRouter } from "next/dist/client/router";
6+
import { supabase } from "../lib/supabase";
7+
import toast from "react-hot-toast";
8+
9+
export default function EditUser() {
10+
const [thisUser, setThisUser] = useState(null);
11+
const { currentUser } = useAuth();
12+
const router = useRouter();
13+
14+
useEffect(() => {
15+
if (currentUser) {
16+
searchUsers(currentUser.email).then((res) => {
17+
if (res == -1) {
18+
router.push("/onboarding");
19+
} else {
20+
getCurrentUser(currentUser.email).then((user) => {
21+
setThisUser(user);
22+
});
23+
}
24+
});
25+
} else {
26+
router.push("/signup");
27+
}
28+
console.log(currentUser);
29+
}, [currentUser, router]);
30+
31+
const [userObject, setUserObject] = useState({
32+
fullName: "",
33+
tags: "",
34+
username: "",
35+
});
36+
37+
useEffect(() => {
38+
if (thisUser) {
39+
setUserObject({
40+
fullName: thisUser.fullName,
41+
tags: thisUser.tags.join(","),
42+
username: thisUser.username,
43+
});
44+
}
45+
}, [thisUser]);
46+
47+
const handleChange = (e) => {
48+
setUserObject({ ...userObject, [e.target.name]: e.target.value });
49+
};
50+
51+
const handleSubmit = async (e) => {
52+
e.preventDefault();
53+
let tagsToBeSent = [];
54+
console.log(userObject);
55+
tagsToBeSent = userObject.tags.split(",");
56+
try {
57+
let res = await supabase
58+
.from("users")
59+
.update({
60+
fullName: userObject.fullName,
61+
tags: tagsToBeSent,
62+
username: userObject.username,
63+
})
64+
.match({ email: currentUser.email });
65+
console.log(res);
66+
67+
if (res.error) {
68+
throw res.error;
69+
}
70+
toast.success("User Updated");
71+
router.push("/profile");
72+
} catch (error) {
73+
console.log(error);
74+
if (error.code == 23505) {
75+
toast.error("Username already taken");
76+
} else {
77+
toast.error("Something went wrong, check your details");
78+
}
79+
}
80+
};
81+
82+
return (
83+
<div className="flex justify-center">
84+
<div className="mt-40 w-5/12 flex flex-col justify-center p-10 bg-gradient-to-br from-primary-start to-primary-end rounded-lg shadow-lg">
85+
{thisUser ? (
86+
<>
87+
<Image
88+
className="pr-20"
89+
src={
90+
"https://avatars.dicebear.com/api/miniavs/" +
91+
userObject.username +
92+
".svg"
93+
}
94+
alt="Avatar"
95+
height="120"
96+
width="120"
97+
/>
98+
<form
99+
className="text-left flex flex-col items-center mt-10 mx-20"
100+
onSubmit={handleSubmit}
101+
>
102+
<div className="my-5 flex flex-row justify-between w-full">
103+
<label className="text-black text-2xl font-thin mr-10">
104+
Full Name (real or Fake)
105+
</label>
106+
<input
107+
className="rounded-lg p-2 focus:outline-none"
108+
name="fullName"
109+
value={userObject.fullName}
110+
onChange={handleChange}
111+
required
112+
placeholder="Full Name"
113+
/>
114+
</div>
115+
<div className="my-5 flex flex-row justify-between w-full">
116+
<label className="text-black text-2xl font-thin mr-10">
117+
Your tags (separated by commas)
118+
</label>
119+
<input
120+
className="rounded-lg p-2 focus:outline-none"
121+
name="tags"
122+
value={userObject.tags}
123+
onChange={handleChange}
124+
required
125+
placeholder="Enter , separated values"
126+
/>
127+
</div>
128+
<div className="my-5 flex flex-row justify-between w-full">
129+
<label className="text-black text-2xl font-thin mr-10">
130+
Username (does <b>COOL</b> things to your dp)
131+
</label>
132+
<input
133+
className="rounded-lg p-2 focus:outline-none"
134+
name="username"
135+
value={userObject.username}
136+
onChange={handleChange}
137+
required
138+
placeholder="Username"
139+
/>
140+
</div>
141+
<button
142+
type="submit"
143+
className=" w-5/12 my-10 mx-5 bg-gradient-to-tr from-secondary-start to-secondary-end shadow-xl hover:bg-opacity-70 text-white font-bold font-mono py-2 px-10 rounded-lg"
144+
>
145+
Update
146+
</button>
147+
<button
148+
type="button"
149+
className=" w-5/12 mx-5 bg-gradient-to-tr from-danger-start to-danger-end shadow-xl hover:bg-opacity-70 text-white font-bold font-mono py-2 px-10 rounded-lg"
150+
onClick={() => router.push("/profile")}
151+
>
152+
Cancel
153+
</button>
154+
</form>
155+
</>
156+
) : null}
157+
</div>
158+
</div>
159+
);
160+
}

β€Žweb/pages/guild/[gid].jsβ€Ž

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export default function GuildDetail() {
1414
setNewClientText(e.target.value);
1515
};
1616

17+
useEffect(() => {
18+
window.scrollTo(0, document.body.scrollHeight);
19+
}, [messages]);
20+
1721
const fetchMessages = async () => {
1822
if (messages.length === 0) {
1923
const fetchedMessages = await supabase
@@ -24,19 +28,25 @@ export default function GuildDetail() {
2428

2529
console.log(fetchedMessages.data);
2630

27-
fetchedMessages?.data?.map(async (message, i) => {
28-
const sender = await supabase
29-
.from("users")
30-
.select("username")
31-
.match({ uid: message.uid });
31+
if (
32+
fetchedMessages?.data !== null &&
33+
fetchedMessages?.data !== undefined
34+
) {
35+
console.log(fetchedMessages.data.length);
36+
for (let i = 0; i < fetchedMessages.data.length; i++) {
37+
const sender = await supabase
38+
.from("users")
39+
.select("username")
40+
.match({ uid: fetchedMessages.data[i].uid });
3241

33-
const newText = new Message({
34-
id: message.mid,
35-
message: message.text,
36-
senderName: sender.data[0].username,
37-
});
38-
setmessages((messages) => [...messages, newText]);
39-
});
42+
const newText = new Message({
43+
id: fetchedMessages.data[i].mid,
44+
message: fetchedMessages.data[i].text,
45+
senderName: sender.data[0].username,
46+
});
47+
setmessages((messages) => [...messages, newText]);
48+
}
49+
}
4050
}
4151
};
4252

@@ -107,23 +117,14 @@ export default function GuildDetail() {
107117
<input
108118
value={newClientText}
109119
onChange={handleChange}
110-
placeholder="Type a message"
120+
onKeyPress={(e) => {
121+
if (e.key === "Enter") {
122+
handleSubmit();
123+
}
124+
}}
125+
placeholder="Type a message and hit return"
111126
className="w-9/12 fixed bottom-10 bg-accentGray rounded-xl h-14 mt-10 text-white p-4 text-lg focus:outline-none"
112127
/>
113-
<div className="w-full flex justify-end">
114-
<div
115-
onClick={() => handleSubmit()}
116-
className="fixed flex items-center pr-3 cursor-pointer hover:opacity-70 justify-center bottom-10 float-right rounded-r-xl bg-primary-solid h-14 w-20"
117-
>
118-
<Image
119-
className="transform rotate-45"
120-
src="/send.svg"
121-
alt="send"
122-
height="30"
123-
width="30"
124-
/>
125-
</div>
126-
</div>
127128
</div>
128129
);
129130
}

β€Žweb/pages/guilds.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function Guilds() {
4848
);
4949

5050
return (
51-
<div className="flex justify-center text-center">
51+
<div className="flex justify-center text-center px-20">
5252
<GuildList />
5353
</div>
5454
);

β€Žweb/pages/home.jsβ€Ž

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import React, { useState, useEffect } from "react";
22
import Image from "next/image";
33
import { supabase } from "../lib/supabase";
4-
import { truncatePost } from "../lib/utils";
4+
import { getTimeOfDay, truncatePost } from "../lib/utils";
55
import Link from "next/link";
6+
import { useAuth } from "../lib/auth";
7+
import { useRouter } from "next/dist/client/router";
68

79
export default function Home() {
810
const [posts, setPosts] = useState(null);
911
const [loading, setLoading] = useState(true);
12+
const { currentUser } = useAuth();
13+
const router = useRouter();
1014

1115
useEffect(() => {
1216
async function fetchPost() {
@@ -24,16 +28,33 @@ export default function Home() {
2428
fetchPost();
2529
}, [posts]);
2630

31+
useEffect(() => {
32+
if (!currentUser) {
33+
router.push("/splash");
34+
}
35+
}, [currentUser, router]);
36+
2737
useEffect(() => {
2838
console.log(posts);
2939
}, [posts]);
3040

3141
return (
3242
<div>
3343
<div className="px-40 flex flex-col items-center justify-between">
34-
<h1 className="text-5xl font-bold font-mono text-white my-10">
35-
Good Morning πŸŒ₯&nbsp;πŸ—ž
36-
</h1>
44+
<div className="flex flex-row items-center justify-between ld:w-10/12 xl:w-1/2">
45+
<h1 className="md:text-lg lg:text-3xl xl:text-5xl font-bold font-mono text-white my-10 mx-10">
46+
{getTimeOfDay(new Date().getHours())} πŸ—ž
47+
</h1>
48+
<button
49+
onClick={() => {
50+
router.push("/posts/edit");
51+
}}
52+
className="h-10 md:text-xs xl:text-md bg-gradient-to-tr from-primary-start to-primary-end shadow-xl hover:bg-opacity-70 text-white font-bold font-mono px-10 rounded-lg"
53+
>
54+
New Post
55+
</button>
56+
</div>
57+
3758
<div className="flex flex-row flex-wrap">
3859
{!loading
3960
? posts.map((post, i) => {

0 commit comments

Comments
Β (0)