Skip to content

Commit

Permalink
✨ Changed some UI in the post pages and cleaned up account page
Browse files Browse the repository at this point in the history
  • Loading branch information
dnrm committed Sep 10, 2022
1 parent 7072182 commit 434d957
Show file tree
Hide file tree
Showing 20 changed files with 814 additions and 963 deletions.
21 changes: 13 additions & 8 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from "react";

const Footer = () => {
return (
<footer className="bg-gray-100 p-6 border-gray-300 border-t-2">
<div className="main">
<h3>© Daniel Medina 2021</h3>
<p>Made with ❤️ and <a href="https://nextjs.org" className="text-blue-700">Next.js</a></p>
</div>
</footer>
);
return (
<footer className="bg-gray-100 p-6 border-gray-300 border-t-2">
<div className="main">
<h3>© Daniel Medina 2021</h3>
<p>
Made with ❤️ and{" "}
<a href="https://nextjs.org" className="text-blue-700">
Next.js
</a>
</p>
</div>
</footer>
);
};

export default Footer;
8 changes: 7 additions & 1 deletion components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from "react";

const Modal = ({ title, hide, confirmDelete }: any) => {
type Props = {
title: string;
hide: () => void;
confirmDelete: () => void;
};

const Modal = ({ title, hide, confirmDelete }: Props) => {
return (
<div className="mt-40 flex justify-between items-center flex-col shadow-xl bg-white overflow-y-auto overflow-x-hidden fixed z-50 max-w-4xl border-gray-200 border-2 rounded-xl mx-auto h-1/3 md:inset-0">
<div className="relative p-4 w-full h-full md:h-auto">
Expand Down
11 changes: 6 additions & 5 deletions components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import { useUserContext } from "../context/user";
const Navbar = () => {
const { data: session, status } = useSession();

let user = useUserContext();

console.log(user);

return (
<nav>
<Head>
Expand All @@ -33,6 +29,11 @@ const Navbar = () => {
<a className={`${styles.mono} text-lg font-normal`}>Dashboard</a>
</Link>
</li>
<li className="px-1 md:px-2 tracking-tighter">
<Link href="/create-post">
<a className={`${styles.mono} text-lg font-normal`}>Publish</a>
</Link>
</li>
</div>
{session && (
<Link href={`/account`}>
Expand All @@ -46,7 +47,7 @@ const Navbar = () => {
// @ts-ignore
src={session.user.image}
// @ts-ignore
alt={'image'}
alt={"image"}
className="rounded-full w-12 h-12 ml-4 shadow-2xl"
/>
</a>
Expand Down
44 changes: 31 additions & 13 deletions components/Post.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from "react";
import Link from "next/link";
import { motion } from "framer-motion";
import Image from "next/image";

type viewMode = "feed" | "dashboard";

Expand All @@ -26,10 +27,14 @@ const Post = ({ src, title, layout, content, id, mode }: Props) => {
};

return (
<div onMouseEnter={showOptions} onMouseLeave={hideOptions}>
<div
onMouseEnter={showOptions}
onMouseLeave={hideOptions}
className="rounded-md"
>
{isHovered && dashboard == "dashboard" ? (
<Link href={`/edit/${id}`}>
<a className="cursor-pointer options bg-gray-200 border-2 border-l-2 absolute p-4 rounded-br-md">
<a className="cursor-pointer options z-30 bg-white border-2 border-l-2 absolute p-4 rounded-br-md">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6"
Expand All @@ -48,35 +53,48 @@ const Post = ({ src, title, layout, content, id, mode }: Props) => {
</Link>
) : null}
<Link href={`/post/${id}`}>
<a>
<a className="rounded-md">
<motion.div
layout="position"
transition={{
duration: 0.3,
}}
className={`border-2 text-black box-border ${
className={`border-2 text-black box-border rounded-md ${
layout === "row" ? "flex justify-start items-center" : null
} ${
layout === "column"
? "h-full flex flex-col items-start justify-start"
: null
}`}
>
<div className={`bg-white pt-3 ${layout === "column" ? "w-full px-3" : "pl-3"}`}>
<div
className={`bg-white pt-3 ${
layout === "column" ? "w-full px-3" : "pl-3"
}`}
>
{src ? (
<img
src={src}
alt=""
className={`object-center rounded-sm object-cover ${
layout === "row" ? "mr-2 w-16 h-16 mb-0 pb-3" : "h-56 w-full"
}`}
/>
<div
className={`relative w-full ${
layout === "row"
? "mr-2 w-16 h-16 mb-0 pb-3"
: "h-56 w-full"
} `}
>
<Image
src={src}
blurDataURL="https://via.placeholder.com/100x100?text=+"
placeholder="blur"
alt=""
layout="fill"
className={`object-center rounded-lg object-cover`}
/>
</div>
) : null}
</div>
<div className="flex flex-col w-full overflow-hidden p-4">
<h1
className={`font-semibold text-xl leading-8 ${
layout === "row" ? "mr-2 min-w-max" : "mr-0"
layout === "row" ? "mr-2 truncate" : "mr-0 truncate "
}`}
>
{title}
Expand Down
121 changes: 64 additions & 57 deletions components/Users.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,73 @@
import React, { useEffect, useState } from "react";
import Link from "next/link";
import TimeAgo from 'react-timeago'
import ReactTooltip from 'react-tooltip'
import TimeAgo from "react-timeago";
import ReactTooltip from "react-tooltip";

const Users = () => {
const [users, setUsers] = useState<Array<any>>([]);
const [users, setUsers] = useState<Array<any>>([]);

useEffect(() => {
const get = async () => {
const response = await fetch("/api/users");
const users = await response.json();
setUsers(users);
};
get();
}, []);
useEffect(() => {
const get = async () => {
const response = await fetch("/api/users");
const users = await response.json();
setUsers(users);
};
get();
}, []);

return (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 py-6">
{users.map((i) => {
return (
<div
className="user-container p-4 shadow-sm rounded-md border-gray-200 border-2 hover:bg-gray-100 flex justify-between items-center"
key={i._id}
>
<Link href={`/users/${i.content}`}>
<a>
<div className="name cursor-pointer">
<h1 className="text-xl sm:text-2xl font-bold tracking-tighter hover:underline">
{i.content}
</h1>
<h2 className="text-sm sm:text-md" data-tip data-for={i._id}>
Joined{" "}
<TimeAgo date={i.date}></TimeAgo>
</h2>
<ReactTooltip getContent={() => new Date(i.date).toDateString()} id={i._id} type="info" />
</div>
</a>
</Link>
<a href={`https://instagram.com/${i.content}`} rel="noreferrer" target="_blank">
<div className="link bg-blue-500 p-4 rounded-lg text-white">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
/>
</svg>
</div>
<span className="hidden">{i.content}</span>
</a>
</div>
);
})}
</div>
);
return (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 py-6">
{users.map((i) => {
return (
<div
className="user-container p-4 shadow-sm rounded-md border-gray-200 border-2 hover:bg-gray-100 flex justify-between items-center"
key={i._id}
>
<Link href={`/users/${i.content}`}>
<a>
<div className="name cursor-pointer">
<h1 className="text-xl sm:text-2xl font-bold tracking-tighter hover:underline">
{i.content}
</h1>
<h2 className="text-sm sm:text-md" data-tip data-for={i._id}>
Joined <TimeAgo date={i.date}></TimeAgo>
</h2>
<ReactToolip
getContent={() => new Date(i.date).toDateString()}
id={i._id}
type="info"
/>
</div>
</a>
</Link>
<a
href={`https://instagram.com/${i.content}`}
rel="noreferrer"
target="_blank"
>
<div className="link bg-blue-500 p-4 rounded-lg text-white">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
/>
</svg>
</div>
<span className="hidden">{i.content}</span>
</a>
</div>
);
})}
</div>
);
};

export default Users;
9 changes: 7 additions & 2 deletions context/posts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { createContext, useContext } from "react";
import useSwr from "swr";
import { PostType } from "../types/Post";
import { createContext, useContext } from "react";

interface PostsContextType {
data: PostType[];
}

const PostsContext = createContext({});
const PostsContext = createContext<Array<PostType> | null>(null);

const fetcher = (...args: [any]) => fetch(...args).then((res) => res.json());

Expand Down
4 changes: 2 additions & 2 deletions lib/mongodb-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function connectToDatabase(database) {

let client = new MongoClient(MONGODB_URI, opts);
await client.connect();
let db = client.db('crystal');
let db = client.db("crystal");

cachedClient = client;
cachedDb = db;
Expand All @@ -33,4 +33,4 @@ export async function connectToDatabase(database) {
client: cachedClient,
db: cachedDb,
};
}
}
24 changes: 12 additions & 12 deletions lib/mongodb.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// This approach is taken from https://github.com/vercel/next.js/tree/canary/examples/with-mongodb
import { MongoClient } from "mongodb"
import { MongoClient } from "mongodb";

const uri = process.env.MONGODB_URI
const uri = process.env.MONGODB_URI;
const options = {
useUnifiedTopology: true,
useNewUrlParser: true,
}
};

let client
let clientPromise
let client;
let clientPromise;

if (!process.env.MONGODB_URI) {
throw new Error("Please add your Mongo URI to .env.local")
throw new Error("Please add your Mongo URI to .env.local");
}

if (process.env.NODE_ENV === "development") {
// In development mode, use a global variable so that the value
// is preserved across module reloads caused by HMR (Hot Module Replacement).
if (!global._mongoClientPromise) {
client = new MongoClient(uri, options)
global._mongoClientPromise = client.connect()
client = new MongoClient(uri, options);
global._mongoClientPromise = client.connect();
}
clientPromise = global._mongoClientPromise
clientPromise = global._mongoClientPromise;
} else {
// In production mode, it's best to not use a global variable.
client = new MongoClient(uri, options)
clientPromise = client.connect()
client = new MongoClient(uri, options);
clientPromise = client.connect();
}

// Export a module-scoped MongoClient promise. By doing this in a
// separate module, the client can be shared across functions.
export default clientPromise
export default clientPromise;
22 changes: 11 additions & 11 deletions middleware/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import nextConnect from 'next-connect'
import multiparty from 'multiparty'
import nextConnect from "next-connect";
import multiparty from "multiparty";

const middleware = nextConnect()
const middleware = nextConnect();

middleware.use(async (req: any, res:any, next: any) => {
const form = new multiparty.Form()
middleware.use(async (req: any, res: any, next: any) => {
const form = new multiparty.Form();

await form.parse(req, function (err: any, fields: any, files: any) {
req.body = fields
req.files = files
next()
})
})
req.body = fields;
req.files = files;
next();
});
});

export default middleware
export default middleware;
Loading

0 comments on commit 434d957

Please sign in to comment.