From f6689d5400241489b7afe79a7c879b5137a0c72e Mon Sep 17 00:00:00 2001 From: GamerBoss101 Date: Sat, 12 Apr 2025 23:26:04 -0400 Subject: [PATCH] Navbar and Post Schema Fixes --- src/app/(app)/page.tsx | 33 ---------------------- src/lib/components/MobileNav.jsx | 11 ++++++-- src/lib/components/NavBar.tsx | 21 ++++++++++++++ src/lib/scripts/Post.ts | 47 ++++++++++++++++++++++++++++---- src/lib/scripts/db.ts | 5 +++- 5 files changed, 76 insertions(+), 41 deletions(-) diff --git a/src/app/(app)/page.tsx b/src/app/(app)/page.tsx index 6d5ab41..8ecf2a6 100644 --- a/src/app/(app)/page.tsx +++ b/src/app/(app)/page.tsx @@ -10,22 +10,6 @@ function Mobile() {

Welcome, {isAuthenticated ? session.username : ""} !!

- {isAuthenticated ? ( -
- -
- ) : ( -
- - -
- )} ); } @@ -38,23 +22,6 @@ function Web() {

Welcome, {isAuthenticated ? session.username : ""} !!

- - {isAuthenticated ? ( -
- -
- ) : ( -
- - -
- )} ); } diff --git a/src/lib/components/MobileNav.jsx b/src/lib/components/MobileNav.jsx index 8f82913..ce24532 100644 --- a/src/lib/components/MobileNav.jsx +++ b/src/lib/components/MobileNav.jsx @@ -6,11 +6,13 @@ import { Home as IconHome, BookText as BookImage, Coins as CoinsImage, + User as UserImage, } from "lucide-react"; -import { useRouter } from "next/navigation"; - const Footer = () => { + + const { isAuthenticated } = useDevice(); + return (
@@ -23,6 +25,11 @@ const Footer = () => { + {isAuthenticated ? ( + + + + ) : null}
); diff --git a/src/lib/components/NavBar.tsx b/src/lib/components/NavBar.tsx index 19a2705..402ce34 100644 --- a/src/lib/components/NavBar.tsx +++ b/src/lib/components/NavBar.tsx @@ -3,8 +3,11 @@ import React from "react"; import Image from "next/image"; +import { useDevice } from "../context/DeviceContext"; const NavBar = () => { + const { isAuthenticated } = useDevice(); + return ( diff --git a/src/lib/scripts/Post.ts b/src/lib/scripts/Post.ts index 17f2d37..106f0ef 100644 --- a/src/lib/scripts/Post.ts +++ b/src/lib/scripts/Post.ts @@ -6,25 +6,62 @@ const reqString = { }; const postSchema = new mongoose.Schema({ + id: reqString, imageDes: reqString, timeStamp: Date, reactions: Array, + userId: reqString, }); -export class Pickup { +export class Post { model: mongoose.Model; upsert: any; constructor() { - this.model = mongoose.model('post', postSchema); + this.model = mongoose.model('posts', postSchema); this.upsert = { upsert: true }; } - async create(imageDes: string, reactions: Array) { + + makeId(length: number) { + var result = []; + var characters = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789'; + var charactersLength = characters.length; + for ( var i = 0; i < length; i++ ) { + result.push(characters.charAt(Math.floor(Math.random() * charactersLength))); + } + return result.join(''); + } + + async create(userId:string, imageDes: string) { const newEntry = new this.model({ + id: this.makeId(5), imageDes: imageDes, timeStamp: new Date().toISOString(), - reactions: reactions, + reactions: [], + userId: userId }); await newEntry.save(); return newEntry; } -} \ No newline at end of file + + async getById(id: string) { + return await this.model.findOne({ id: id }); + } + + async getAll() { + return await this.model.find({}); + } + + async getAllByUserId(userId: string) { + return await this.model.find({ userId: userId }); + } + + async update(id: string, imageDes: string) { + return await this.model.updateOne({ id: id }, { imageDes: imageDes }); + } + + async delete(id: string) { + return await this.model.deleteOne({ id: id }); + } +} + +export default Post; \ No newline at end of file diff --git a/src/lib/scripts/db.ts b/src/lib/scripts/db.ts index da6f34b..501bd8e 100644 --- a/src/lib/scripts/db.ts +++ b/src/lib/scripts/db.ts @@ -1,11 +1,14 @@ import mongoose from "mongoose"; -import User from "./User"; +import User from "./User"; +import Post from "./Post"; class DB { users: User; + posts: Post; constructor() { this.users = new User(); + this.posts = new Post(); this.connect(); }