Skip to content

Commit

Permalink
final fixes (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
harisarang authored Oct 11, 2021
2 parents 4917d23 + 4a6754b commit ab7cae9
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 125 deletions.
45 changes: 24 additions & 21 deletions web/components/RefinementList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,31 @@ const RefinementList = ({
searchForItems,
createURL,
}) => (
<ul className="flex justify-center mt-10">
<ul className=" hidden lg:flex lg:justify-center lg:mt-10 lg:mx-10">
<span className="text-white font-bold">Filter By:</span>
{items.map((item) => (
<span key={item.label}>
<a
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"
href={createURL(item.value)}
style={{ backgroundColor: item.isRefined ? "#59AF77" : "" }}
onClick={(event) => {
event.preventDefault();
refine(item.value);
}}
>
{isFromSearch ? (
<Highlight attribute="label" hit={item} />
) : (
item.label
)}{" "}
({item.count})
</a>
</span>
))}
{items.map((item, i) => {
if (i < 6)
return (
<span key={item.label}>
<a
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"
href={createURL(item.value)}
style={{ backgroundColor: item.isRefined ? "#59AF77" : "" }}
onClick={(event) => {
event.preventDefault();
refine(item.value);
}}
>
{isFromSearch ? (
<Highlight attribute="label" hit={item} />
) : (
item.label
)}{" "}
({item.count})
</a>
</span>
);
})}
</ul>
);

Expand Down
4 changes: 2 additions & 2 deletions web/components/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function SearchBar({ currentRefinement, refine, placeholder = "Search" }) {
return (
<div className="w-full flex justify-center">
<div className="absolute w-8/12 h-14 flex justify-end items-center ">
<div className="bg-secondary-solid z-20 h-14 w-1/6 rounded-r-lg flex items-center divide-x divide-white">
<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">
<button
onClick={() => router.push("/explore/people")}
className="w-1/2 h-full hover:bg-primary-solid"
Expand All @@ -20,7 +20,7 @@ function SearchBar({ currentRefinement, refine, placeholder = "Search" }) {
</button>
<button
onClick={() => router.push("/explore/blog")}
className="w-1/2 h-full hover:bg-primary-solid hover:rounded-r-lg"
className="w-1/2 h-full hover:bg-primary-solid rounded-r-lg"
>
<div className="text-sm">πŸ“°</div>
<div className="text-sm font-mono font-medium text-white">Blog</div>
Expand Down
12 changes: 12 additions & 0 deletions web/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ export const truncatePost = (post) => {
}
return post;
};

export const getTimeOfDay = (hour) => {
if (hour >= 5 && hour < 12) {
return "Good Morning πŸŒ₯";
} else if (hour >= 12 && hour < 17) {
return "Good Afternoon 🌞";
} else if (hour >= 17 && hour < 20) {
return "Good Evening πŸŒ‡";
} else {
return "Good Night 🌘";
}
};
160 changes: 160 additions & 0 deletions web/pages/edituser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import React, { useEffect, useState } from "react";
import { useAuth } from "../lib/auth";
import { getCurrentUser, searchUsers, signOut } from "../lib/connection";
import Image from "next/image";
import { useRouter } from "next/dist/client/router";
import { supabase } from "../lib/supabase";
import toast from "react-hot-toast";

export default function EditUser() {
const [thisUser, setThisUser] = useState(null);
const { currentUser } = useAuth();
const router = useRouter();

useEffect(() => {
if (currentUser) {
searchUsers(currentUser.email).then((res) => {
if (res == -1) {
router.push("/onboarding");
} else {
getCurrentUser(currentUser.email).then((user) => {
setThisUser(user);
});
}
});
} else {
router.push("/signup");
}
console.log(currentUser);
}, [currentUser, router]);

const [userObject, setUserObject] = useState({
fullName: "",
tags: "",
username: "",
});

useEffect(() => {
if (thisUser) {
setUserObject({
fullName: thisUser.fullName,
tags: thisUser.tags.join(","),
username: thisUser.username,
});
}
}, [thisUser]);

const handleChange = (e) => {
setUserObject({ ...userObject, [e.target.name]: e.target.value });
};

const handleSubmit = async (e) => {
e.preventDefault();
let tagsToBeSent = [];
console.log(userObject);
tagsToBeSent = userObject.tags.split(",");
try {
let res = await supabase
.from("users")
.update({
fullName: userObject.fullName,
tags: tagsToBeSent,
username: userObject.username,
})
.match({ email: currentUser.email });
console.log(res);

if (res.error) {
throw res.error;
}
toast.success("User Updated");
router.push("/profile");
} catch (error) {
console.log(error);
if (error.code == 23505) {
toast.error("Username already taken");
} else {
toast.error("Something went wrong, check your details");
}
}
};

return (
<div className="flex justify-center">
<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">
{thisUser ? (
<>
<Image
className="pr-20"
src={
"https://avatars.dicebear.com/api/miniavs/" +
userObject.username +
".svg"
}
alt="Avatar"
height="120"
width="120"
/>
<form
className="text-left flex flex-col items-center mt-10 mx-20"
onSubmit={handleSubmit}
>
<div className="my-5 flex flex-row justify-between w-full">
<label className="text-black text-2xl font-thin mr-10">
Full Name (real or Fake)
</label>
<input
className="rounded-lg p-2 focus:outline-none"
name="fullName"
value={userObject.fullName}
onChange={handleChange}
required
placeholder="Full Name"
/>
</div>
<div className="my-5 flex flex-row justify-between w-full">
<label className="text-black text-2xl font-thin mr-10">
Your tags (separated by commas)
</label>
<input
className="rounded-lg p-2 focus:outline-none"
name="tags"
value={userObject.tags}
onChange={handleChange}
required
placeholder="Enter , separated values"
/>
</div>
<div className="my-5 flex flex-row justify-between w-full">
<label className="text-black text-2xl font-thin mr-10">
Username (does <b>COOL</b> things to your dp)
</label>
<input
className="rounded-lg p-2 focus:outline-none"
name="username"
value={userObject.username}
onChange={handleChange}
required
placeholder="Username"
/>
</div>
<button
type="submit"
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"
>
Update
</button>
<button
type="button"
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"
onClick={() => router.push("/profile")}
>
Cancel
</button>
</form>
</>
) : null}
</div>
</div>
);
}
55 changes: 28 additions & 27 deletions web/pages/guild/[gid].js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default function GuildDetail() {
setNewClientText(e.target.value);
};

useEffect(() => {
window.scrollTo(0, document.body.scrollHeight);
}, [messages]);

const fetchMessages = async () => {
if (messages.length === 0) {
const fetchedMessages = await supabase
Expand All @@ -24,19 +28,25 @@ export default function GuildDetail() {

console.log(fetchedMessages.data);

fetchedMessages?.data?.map(async (message, i) => {
const sender = await supabase
.from("users")
.select("username")
.match({ uid: message.uid });
if (
fetchedMessages?.data !== null &&
fetchedMessages?.data !== undefined
) {
console.log(fetchedMessages.data.length);
for (let i = 0; i < fetchedMessages.data.length; i++) {
const sender = await supabase
.from("users")
.select("username")
.match({ uid: fetchedMessages.data[i].uid });

const newText = new Message({
id: message.mid,
message: message.text,
senderName: sender.data[0].username,
});
setmessages((messages) => [...messages, newText]);
});
const newText = new Message({
id: fetchedMessages.data[i].mid,
message: fetchedMessages.data[i].text,
senderName: sender.data[0].username,
});
setmessages((messages) => [...messages, newText]);
}
}
}
};

Expand Down Expand Up @@ -107,23 +117,14 @@ export default function GuildDetail() {
<input
value={newClientText}
onChange={handleChange}
placeholder="Type a message"
onKeyPress={(e) => {
if (e.key === "Enter") {
handleSubmit();
}
}}
placeholder="Type a message and hit return"
className="w-9/12 fixed bottom-10 bg-accentGray rounded-xl h-14 mt-10 text-white p-4 text-lg focus:outline-none"
/>
<div className="w-full flex justify-end">
<div
onClick={() => handleSubmit()}
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"
>
<Image
className="transform rotate-45"
src="/send.svg"
alt="send"
height="30"
width="30"
/>
</div>
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion web/pages/guilds.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function Guilds() {
);

return (
<div className="flex justify-center text-center">
<div className="flex justify-center text-center px-20">
<GuildList />
</div>
);
Expand Down
29 changes: 25 additions & 4 deletions web/pages/home.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React, { useState, useEffect } from "react";
import Image from "next/image";
import { supabase } from "../lib/supabase";
import { truncatePost } from "../lib/utils";
import { getTimeOfDay, truncatePost } from "../lib/utils";
import Link from "next/link";
import { useAuth } from "../lib/auth";
import { useRouter } from "next/dist/client/router";

export default function Home() {
const [posts, setPosts] = useState(null);
const [loading, setLoading] = useState(true);
const { currentUser } = useAuth();
const router = useRouter();

useEffect(() => {
async function fetchPost() {
Expand All @@ -24,16 +28,33 @@ export default function Home() {
fetchPost();
}, [posts]);

useEffect(() => {
if (!currentUser) {
router.push("/splash");
}
}, [currentUser, router]);

useEffect(() => {
console.log(posts);
}, [posts]);

return (
<div>
<div className="px-40 flex flex-col items-center justify-between">
<h1 className="text-5xl font-bold font-mono text-white my-10">
Good Morning πŸŒ₯&nbsp;πŸ—ž
</h1>
<div className="flex flex-row items-center justify-between ld:w-10/12 xl:w-1/2">
<h1 className="md:text-lg lg:text-3xl xl:text-5xl font-bold font-mono text-white my-10 mx-10">
{getTimeOfDay(new Date().getHours())} πŸ—ž
</h1>
<button
onClick={() => {
router.push("/posts/edit");
}}
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"
>
New Post
</button>
</div>

<div className="flex flex-row flex-wrap">
{!loading
? posts.map((post, i) => {
Expand Down
Loading

0 comments on commit ab7cae9

Please sign in to comment.