Skip to content

Commit

Permalink
created post and imageSlider
Browse files Browse the repository at this point in the history
  • Loading branch information
Aamil13 committed Sep 27, 2024
1 parent f21703a commit 69547c5
Show file tree
Hide file tree
Showing 24 changed files with 968 additions and 70 deletions.
52 changes: 30 additions & 22 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
// Load environment variables
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('dotenv').config();

const nextConfig = {
async headers() {
return [
{
// matching all API routes
source: "/api/:path*",
headers: [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" },
{ key: "Access-Control-Allow-Methods", value: "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
{ key: "Access-Control-Allow-Headers", value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" },
]
}
]
}


}
// Configuration object tells the next-pwa plugin
// Import PWA plugin
// eslint-disable-next-line @typescript-eslint/no-var-requires
const withPWA = require("next-pwa")({
dest: "public", // Destination directory for the PWA files
Expand All @@ -28,7 +11,32 @@ const withPWA = require("next-pwa")({
skipWaiting: true, // Skip waiting for service worker activation
});

// Export the combined configuration for Next.js with PWA support
module.exports = withPWA(nextConfig);
// Next.js configuration
const nextConfig = {
// Allow images from external domains
images: {
domains: ['cdn.pixabay.com',"res.cloudinary.com","upload.wikimedia.org"],
},

// module.exports = nextConfig
// Custom headers for API routes
async headers() {
return [
{
// Matching all API routes
source: "/api/:path*",
headers: [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" }, // Be cautious with "*"
{ key: "Access-Control-Allow-Methods", value: "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
{
key: "Access-Control-Allow-Headers",
value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
},
],
},
];
},
};


module.exports = withPWA(nextConfig);
2 changes: 1 addition & 1 deletion src/app/community/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Page = () => {
data: communityGroupPost,
isFetching: communityGroupPostLoading,
isError,
} = useGetCommunityGroupPost(currSelectedGroup?._id, isJoinedInGroup)
} = useGetCommunityGroupPost(currSelectedGroup?._id, isJoinedInGroup, true)

const modalContent = (modalContentType: string) => {
switch (modalContentType) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/timeline/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const Timeline = () => {
const [isModalOpen, setIsModalOpen] = useState(false)
const { userData, userProfileData } = useUniStore()
const [modalContentType, setModalContentType] = useState<ModalContentType>()
const { isLoading, data: TimelinePosts, error } = useGetTimelinePosts()
const { isLoading, data: TimelinePosts, error } = useGetTimelinePosts(true)
const timelinePosts = TimelinePosts?.timelinePosts

const modalContent = (modalContentType: string) => {
Expand Down
27 changes: 27 additions & 0 deletions src/app/v2/community/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import LeftNavWrapper from '@/components/molecules/LeftNavWrapper'
import UniversityCard from '@/components/molecules/UniversityCard'
import PostContainer from '@/components/organisms/PostsContainer'
import UserPostContainer from '@/components/organisms/UserPostContainer'
import { PostInputType } from '@/types/constants'
import React from 'react'

const Community = () => {
return (
<LeftNavWrapper>
<UniversityCard
universityLogo={''}
universityName={'Lorem University'}
isAiPowered={true}
joinedSince={'07/12/23'}
description={
'Official community page for Lorem University. For inquiries contact the Human Resources Department in B-Wing of Northern Campus.'
}
memberCount={200}
/>
<UserPostContainer type={PostInputType.Community} />
<PostContainer />
</LeftNavWrapper>
)
}

export default Community
2 changes: 1 addition & 1 deletion src/app/v2/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Register = () => {
}
}, [])
return (
<div className="flex h-screen ">
<div className="flex h-screen bg-white">
{loading ? (
<Loading />
) : (
Expand Down
26 changes: 7 additions & 19 deletions src/app/v2/timeline/page.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import LeftNavWrapper from '@/components/molecules/LeftNavWrapper'
import UniversityCard from '@/components/molecules/UniversityCard'
import LeftNavbar from '@/components/organisms/LeftNavbar'
import PostContainer from '@/components/organisms/PostsContainer'
import UserPostContainer from '@/components/organisms/UserPostContainer'
import { PostInputType } from '@/types/constants'
import React from 'react'

export default function Timeline() {
return (
<div className="flex h-screen gap-8 py-8 px-4">
<div className="w-1/5 hidden md:block">
<LeftNavbar />
</div>
<div className="w-3/5">
<UniversityCard
universityLogo={''}
universityName={'Lorem University'}
isAiPowered={true}
joinedSince={'07/12/23'}
description={
'Official community page for Lorem University. For inquiries contact the Human Resources Department in B-Wing of Northern Campus.'
}
memberCount={200}
/>
<UserPostContainer />
</div>
<div className="w-1/5 rounded-2xl shadow-2xl bg-white hidden lg:block"></div>
</div>
<LeftNavWrapper>
<UserPostContainer type={PostInputType.Timeline} />
<PostContainer />
</LeftNavWrapper>
)
}
81 changes: 81 additions & 0 deletions src/components/atoms/PostCardImagesGrid/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react'
import Image from 'next/image'
import { PostType } from '@/types/constants'

type props = {
images: {
imageUrl: string
}[]
setImageCarasol: React.Dispatch<
React.SetStateAction<{
isShow: boolean
images: any
currImageIndex: number | null
}>
>
idx: number
type: PostType.Community | PostType.Timeline
}

const DynamicImageContainer = ({ images, setImageCarasol }: props) => {
const imageCount = images?.length

if (imageCount == 0) {
return <div></div>
}

const handleImageClick = (index: number) => {
setImageCarasol({
isShow: true,
images: images,
currImageIndex: index,
})
}
const getGridTemplate = () => {
switch (imageCount) {
case 1:
return 'grid-cols-1'
case 2:
return 'grid-cols-2'
case 3:
return 'grid-cols-2 grid-rows-2'
case 4:
return 'grid-cols-3 grid-rows-2'
default:
return 'grid-cols-3 grid-rows-2'
}
}

return (
<div className={`grid gap-2 ${getGridTemplate()} w-full h-80 px-4 mx-auto`}>
{images?.slice(0, 4).map((src, index) => (
<div
key={index}
className={`relative overflow-hidden flex ${imageCount == 1 && 'h-80'} ${imageCount == 2 && 'h-80'} ${
imageCount === 3 && index === 2 && 'col-span-2 '
} ${imageCount === 4 && index === 2 ? 'row-span-2 ' : ''} ${imageCount >= 4 && index === 2 && 'row-span-2 '} ${
imageCount >= 4 && index === 3 && 'col-span-2 '
} `}
onClick={() => handleImageClick(index)}
>
<Image
layout="fill"
objectFit="cover"
objectPosition="center"
key={index}
src={src.imageUrl}
alt={`Image ${index + 1}`}
className="rounded-lg "
/>
{imageCount > 4 && index == 2 && (
<div className="absolute bg-slate-50 shadow-lg w-40 h-40 -right-10 -bottom-10 rounded-full text-neutral-700 flex items-center justify-center">
+{imageCount - 4}
</div>
)}
</div>
))}
</div>
)
}

export default DynamicImageContainer
47 changes: 47 additions & 0 deletions src/components/atoms/PostCardOption/PostCartOption.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use client'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/Popover'
import Link from 'next/link'

import React from 'react'
import { FiMoreHorizontal } from 'react-icons/fi'
import { HiOutlineBell, HiOutlineFlag } from 'react-icons/hi'
import { MdOutlineBookmarkBorder, MdOutlineOpenInNew } from 'react-icons/md'

interface PostOptionType {
postID: string
isType: string
}

const PostCartOption = ({ postID, isType }: PostOptionType) => {
return (
<Popover>
<PopoverTrigger>
<FiMoreHorizontal />
</PopoverTrigger>
<PopoverContent className="relative right-16 bottom-16 w-auto p-5 border-none shadow-lg bg-white shadow-gray-light">
<div className="flex flex-col gap-5">
<div className="flex gap-1 items-center">
<Link className="flex gap-1 items-center" href={`/post/${postID}?isType=${isType}`}>
<MdOutlineOpenInNew className="text-primary" size={20} />
<p className="font-medium text-sm">Open Post</p>
</Link>
</div>
<div className="flex gap-1 items-center">
<MdOutlineBookmarkBorder className="text-primary" size={20} />
<p className="font-medium text-sm">Save Post</p>
</div>
<div className="flex gap-1 items-center">
<HiOutlineBell className="text-primary" size={20} />
<p className="font-medium text-sm">Mute Post from</p>
</div>
<div className="flex gap-1 items-center">
<HiOutlineFlag className="text-primary" size={20} />
<p className="font-medium text-sm">Report this Post</p>
</div>
</div>
</PopoverContent>
</Popover>
)
}

export default PostCartOption
22 changes: 22 additions & 0 deletions src/components/atoms/PostImageSlider/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.swiper {
width: 100%;
height: 100%;
}

.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;

/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
}

.swiper-slide img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
46 changes: 46 additions & 0 deletions src/components/atoms/PostImageSlider/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react'
// Import Swiper React components
import { Swiper, SwiperSlide } from 'swiper/react'

// Import Swiper styles
import 'swiper/css'
import 'swiper/css/pagination'
import 'swiper/css/navigation'

import './index.css'

// import required modules
import { Keyboard, Pagination, Navigation } from 'swiper/modules'
import Image from 'next/image'

type prop = {
images: { imageUrl: string }[]
initialSlide: number | null
}

export default function PostImageSlider({ images, initialSlide }: prop) {
return (
<div className="z-40 fixed w-[60%] top-1/4 h-3/6 ">
<Swiper
slidesPerView={1}
spaceBetween={30}
keyboard={{
enabled: true,
}}
pagination={{
clickable: true,
}}
navigation={true}
modules={[Keyboard, Navigation]}
initialSlide={initialSlide || 0}
className="mySwiper "
>
{images?.map((item: any) => (
<SwiperSlide key={item?.imageUrl}>
{<Image layout="fill" objectFit="cover" objectPosition="center" src={item?.imageUrl} alt="item" />}
</SwiperSlide>
))}
</Swiper>
</div>
)
}
8 changes: 4 additions & 4 deletions src/components/communityUniversity/GroupSelectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const GroupSelectors = ({ setCurrSelectedGroup, currSelectedGroup, data }: any)
currSelectedGroup?.title == data?.title
? 'bg-[#F3F2FF] max-md:bg-white max-md:after:h-[4px] after:rounded-full'
: 'border-t-2 max-md:border-0 border-neutral-300'
} flex w-full justify-between items-center gap-1 py-2 px-3 first-of-type:border-0 relative after:content-[''] after:absolute after:left-3 after:z-30 after:top-[calc(90%+10px)] after:w-[calc(60%)] after:bg-[#6647FF] `}
} flex w-full gap-2 items-center gap-1 py-2 px-3 first-of-type:border-0 relative after:content-[''] after:absolute after:left-3 after:z-30 after:top-[calc(90%+10px)] after:w-[calc(60%)] after:bg-[#6647FF] `}
>
{data?.communityGroupLogoUrl?.imageUrl ? (
<img className="w-10 h-10 object-cover rounded-full" src={data?.communityGroupLogoUrl.imageUrl} alt="dp" />
) : (
<div className="w-10 h-10 object-cover rounded-full bg-orange"></div>
<div className="w-10 h-10 object-cover rounded-full bg-green-500 z-10"></div>
)}
<label className=" max-md:hidden font-medium text-sm text-center">{data.title}</label>
<FaStar className="max-md:hidden" size={24} color="#F59E0B" />
<label className=" max-md:hidden font-medium text-xs ">{data.title}</label>
{/* <FaStar className="max-md:hidden" size={24} color="#F59E0B" /> */}
</div>
)
}
Expand Down
Loading

0 comments on commit 69547c5

Please sign in to comment.