Skip to content

Commit

Permalink
integrated cloudinary widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Swarga-codes committed May 22, 2024
1 parent 2a9a464 commit f6d1b14
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 4 deletions.
13 changes: 13 additions & 0 deletions app/api/memories/createMemories/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextRequest, NextResponse } from "next/server";

export async function POST(req:NextRequest){
try{
const {title,description,memoryCoverPic,memoryParticipants}=await req.json()
if(!title || memoryParticipants.length===0) return NextResponse.json({success:false,message:'One or more fields are missing!'},{status:422})

}
catch(err){
console.log(err)
return NextResponse.json({success:false,message:"Could not create memory, try again!"},{status:500})
}
}
14 changes: 14 additions & 0 deletions app/api/sample/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NextRequest, NextResponse } from "next/server";

export async function POST(req:NextRequest){

try{
const {imagePath}=await req.json()
console.log(await req.json())

return NextResponse.json({success:true},{status:200})
}
catch(err){
console.log(err)
}
}
26 changes: 26 additions & 0 deletions app/models/fileSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import mongoose from "mongoose";
const {ObjectId}=mongoose.Schema.Types
const fileSchema=new mongoose.Schema({
fileName:{
type:String,
required:true
},
fileUrl:{
type:String,
required:true
},
createdBy:{
type:ObjectId,
ref:'USER'
},
memoryName:{
type:ObjectId,
ref:'MEMORY'
}
},{
timestamps:true
})

const FILE=mongoose.models.FILE || mongoose.model('FILE',fileSchema)

export default FILE;
32 changes: 28 additions & 4 deletions app/ui/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
'use client'
import { Fragment } from 'react'
import { Fragment, useEffect, useRef, useState } from 'react'
import { Disclosure, Menu, Transition } from '@headlessui/react'
import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'
import Image from 'next/image'
import { useRouter } from "next/navigation";
import toast from 'react-hot-toast'
import { CldUploadWidget } from 'next-cloudinary'
function classNames(...classes:string[]) {
return classes.filter(Boolean).join(' ')
}


export default function Navbar() {
const router=useRouter()
const [imageUrl,setImageUrl]=useState([])

async function logout(){
const response=await fetch('/api/auth/logout',{
method:'POST',
Expand All @@ -24,6 +28,9 @@ export default function Navbar() {
router.push('/login')
}
}
useEffect(()=>{
console.log(imageUrl)
},[imageUrl])
return (
<Disclosure as="nav" className="bg-gray-800">
{({ open }) => (
Expand Down Expand Up @@ -64,12 +71,29 @@ export default function Navbar() {
<span className="sr-only">View notifications</span>

</button>
<button className='flex mr-6 border-2 border-blue-500 bg-blue-500 p-2 rounded-lg'>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5" />


<CldUploadWidget uploadPreset="memories" onSuccess={(results) => {
setImageUrl((prevImages)=>[...prevImages,{fileName:results?.info?.original_filename, fileUrl:results?.info?.secure_url}])
}}>
{({ open, isLoading }) => {
return (
<>
{!isLoading? <button className='flex mr-6 border-2 border-blue-500 bg-blue-500 p-2 rounded-lg' onClick={()=>open()}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5" />
</svg>
<span className='font-bold ml-2'>Create a Memory</span>
</button>
:
<button className='flex mr-6 border-2 border-blue-500 bg-blue-500 p-2 rounded-lg'>

<span className='font-bold ml-2'>Loading....</span>
</button>
}
</> );
}}
</CldUploadWidget>
{/* Profile dropdown */}
<Menu as="div" className="relative ml-3">
<div>
Expand Down
65 changes: 65 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lucide-react": "^0.378.0",
"mongoose": "^8.4.0",
"next": "14.2.3",
"next-cloudinary": "^6.5.2",
"react": "^18",
"react-dom": "^18",
"react-hot-toast": "^2.4.1"
Expand Down

0 comments on commit f6d1b14

Please sign in to comment.