Skip to content

Commit

Permalink
fixes: network
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkondle-dev committed Jul 16, 2024
1 parent 74dc0fc commit 9b5141e
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 127 deletions.
32 changes: 17 additions & 15 deletions app/(private)/network/[username]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const ProfilePage = ({ params: { username } }: { params: { username: string } })
<ProfileInfo username={username} profile={profile} />
{Array.isArray(profile?.posts) && (
<Paper p="md" mt="lg" withBorder>
{profile?.posts.length ? (
{profile?.posts?.length ? (
<SimpleGrid cols={{ base: 1, xs: 2, md: 3 }}>
{profile?.posts.map((post: any) => (
{profile?.posts?.map((post: any) => (
<Image
key={String(post?._id)}
src={post?.url}
Expand All @@ -49,19 +49,21 @@ const ProfilePage = ({ params: { username } }: { params: { username: string } })
)}
</Paper>
)}
<Modal
size="md"
styles={{ body: { padding: 0 } }}
opened={!!opened}
onClose={() => setOpened(0)}
withCloseButton={false}
>
<Post
post={profile?.posts.find((post: any) => post?._id === opened)}
user={session?.data?.user._id}
refetch={() => getProfile()}
/>
</Modal>
{Array.isArray(profile?.posts) && profile?.posts?.length && (
<Modal
size="md"
styles={{ body: { padding: 0 } }}
opened={!!opened}
onClose={() => setOpened(0)}
withCloseButton={false}
>
<Post
post={profile?.posts?.find((post: any) => post?._id === opened)}
user={session?.data?.user._id}
refetch={() => getProfile()}
/>
</Modal>
)}
</Container>
);
};
Expand Down
4 changes: 2 additions & 2 deletions app/(private)/network/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const NetworkPage = () => {
};

return (
<Container px={0} size="sm">
<Container px={0} size="md">
<Group mb="md" justify="space-between">
<Title order={3}>Network</Title>
<Button
Expand All @@ -54,7 +54,7 @@ const NetworkPage = () => {
Upload
</Button>
</Group>
<Container px={0} size="xs">
<Container mt="md" px={0} size="xs">
{Array.isArray(posts) && (
<Stack>
{posts?.map((post) => (
Expand Down
10 changes: 10 additions & 0 deletions app/(private)/network/suggested/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { Suggested } from '@/components/Network';

const page = () => (
<>
<Suggested />
</>
);

export default page;
10 changes: 6 additions & 4 deletions app/api/network/posts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ export async function GET() {
const to = await Spark.find({ by: session.user?._id, isAccepted: true }).select('to');
const posts = await Post.find({
$or: [{ user: { $in: to.map((t) => t.to) } }, { user: session.user?._id }],
}).populate({
path: 'user',
select: 'name username image',
});
})
.populate({
path: 'user',
select: 'name username image',
})
.sort('-createdAt');
return NextResponse.json(posts, { status: 200 });
} catch (error: any) {
return NextResponse.json({ error: error?.message }, { status: 500 });
Expand Down
18 changes: 14 additions & 4 deletions app/api/profile/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,28 @@ export async function GET(req: NextRequest) {
'name username image bio city interests dob'
);
}
const by = await Spark.find({ by: user?._id });
const to = await Spark.find({ to: user?._id });
const by = await Spark.find({ by: user?._id })
.populate({
path: 'to',
select: 'name username image',
})
.select('-createdAt -updatedAt -__v');
const to = await Spark.find({ to: user?._id })
.populate({
path: 'by',
select: 'name username image',
})
.select('-createdAt -updatedAt -__v');
const posts = await Post.find({ user: user?._id }).populate({
path: 'user',
select: 'name username image',
});
const isSparked = await Spark.findOne({
to: user?._id,
by: session?.user._id,
//! isAccepted: true,
// isAccepted: true,
});
if (!isSparked) {
if (!isSparked && user?._id === session?.user._id) {
return NextResponse.json(
{ user, by: by?.length, to: to?.length, posts: posts?.length, isSparked: !!isSparked },
{ status: 200 }
Expand Down
2 changes: 1 addition & 1 deletion app/api/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const dynamic = 'force-dynamic';
export async function POST(req: Request) {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
if (!session?.user || !session?.user?.isAdmin) {
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
await startDb();
Expand Down
2 changes: 1 addition & 1 deletion components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
{data?.user?.username}
</Text>
<Stack align="center" gap={rem(4)}>
<FileButton accept="image/png,image/jpeg" onChange={setFile}>
<FileButton accept="image/*" onChange={setFile}>
{(props) => (
<Avatar
variant="filled"
Expand Down
34 changes: 18 additions & 16 deletions components/Network/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ export const Post = ({ post, user, refetch }: Props) => {
</Group>
</Paper>
{post?.caption && (
<Spoiler
maxHeight={50}
showLabel={
<Text size="sm" px="xs">
Show more
<Paper radius={0} withBorder>
<Spoiler
maxHeight={50}
showLabel={
<Text size="sm" px="xs">
Show more
</Text>
}
hideLabel={
<Text size="sm" px="xs">
Hide
</Text>
}
>
<Text size="sm" p="xs">
{post?.caption}
</Text>
}
hideLabel={
<Text size="sm" px="xs">
Hide
</Text>
}
>
<Text size="sm" p="xs">
{post?.caption}
</Text>
</Spoiler>
</Spoiler>
</Paper>
)}
</Card>
</>
Expand Down
Loading

0 comments on commit 9b5141e

Please sign in to comment.