Skip to content

Commit

Permalink
feat(client): improve user experience
Browse files Browse the repository at this point in the history
  • Loading branch information
lareii committed Sep 10, 2024
1 parent b90c16a commit c39b33b
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 59 deletions.
13 changes: 5 additions & 8 deletions client/app/(auth)/login/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { set, useForm } from 'react-hook-form';
import { z } from 'zod';
import { LoaderCircle } from 'lucide-react';
import { Button } from '@/components/ui/button';
Expand All @@ -31,11 +31,7 @@ export default function Page() {
const { toast } = useToast();

const form = useForm({
resolver: zodResolver(formSchema),
defaultValues: {
username: '',
password: ''
}
resolver: zodResolver(formSchema)
});

async function onSubmit(values) {
Expand All @@ -48,6 +44,7 @@ export default function Page() {
description: 'bir hata oluştu. lütfen daha sonra tekrar deneyin.',
duration: 3000
});
setIsSubmitting(false);
return;
}
if (response.status === 401) {
Expand All @@ -56,10 +53,10 @@ export default function Page() {
description: 'kullanıcı adı veya parola yanlış.',
duration: 3000
});
setIsSubmitting(false);
return;
}

form.reset();
setIsSubmitting(false);
router.push('/app');
router.refresh();
Expand Down Expand Up @@ -105,7 +102,7 @@ export default function Page() {
<FormItem className='space-y-1'>
<FormLabel>parola</FormLabel>
<FormControl>
<Input type='password' className='text-xs' {...field} />
<Input type='password' {...field} />
</FormControl>
<FormMessage />
</FormItem>
Expand Down
3 changes: 3 additions & 0 deletions client/app/app/explore/guilds/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return 'çöplükler';
}
39 changes: 39 additions & 0 deletions client/app/app/explore/layout-content.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client';

import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { motion, AnimatePresence } from 'framer-motion';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';

export default function LayoutContent({ children }) {
const pathname = usePathname();
const path = pathname.split('/')[3];

return (
<Tabs value={path}>
<TabsList className='grid w-full grid-cols-3'>
<TabsTrigger value='posts' asChild>
<Link href='/app/explore/posts'>çöpler</Link>
</TabsTrigger>
<TabsTrigger value='guilds' asChild>
<Link href='/app/explore/guilds'>çöplükler</Link>
</TabsTrigger>
<TabsTrigger value='users' asChild>
<Link href='/app/explore/users'>çöpçüler</Link>
</TabsTrigger>
</TabsList>
<AnimatePresence mode='wait'>
<motion.div
key={path}
initial={{ y: 20, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
transition={{ ease: 'easeInOut', duration: 0.3 }}
>
<TabsContent value='posts'>{children}</TabsContent>
<TabsContent value='guilds'>{children}</TabsContent>
<TabsContent value='users'>{children}</TabsContent>
</motion.div>
</AnimatePresence>
</Tabs>
);
}
4 changes: 3 additions & 1 deletion client/app/app/explore/layout.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import LayoutContent from "@/app/app/explore/layout-content";

export const metadata = {
title: 'keşfet'
};

export default function Layout({ children }) {
return children;
return <LayoutContent>{children}</LayoutContent>;
}
36 changes: 0 additions & 36 deletions client/app/app/explore/page.jsx

This file was deleted.

14 changes: 14 additions & 0 deletions client/app/app/explore/posts/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';

import PostList from '@/components/app/Post/List';
import { getPosts } from '@/lib/api/posts';

export default function Page() {
const fetchPosts = async (offset) => {
return await getPosts(11, offset);
};

return (
<PostList fetchPosts={fetchPosts} />
);
}
12 changes: 12 additions & 0 deletions client/app/app/explore/users/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client';

import UserList from '@/components/app/User/List';
import { getUsers } from '@/lib/api/users';

export default function Page() {
const fetchUsers = async (offset) => {
return await getUsers(11, offset);
};

return <UserList fetchUsers={fetchUsers} />;
}
2 changes: 1 addition & 1 deletion client/app/app/users/[slug]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function Page({ params }) {
</>
)}
<div className='mt-10'>
<div className='text-xs text-zinc-400 mb-5'>çöpler</div>
<div className='text-xs text-zinc-400 mb-3'>çöpler</div>
<PostList fetchPosts={fetchPosts} />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/components/app/Navbar/Collapsed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function Collapsed({ router, pathname }) {
useEffect(() => {
if (pathname === '/app') {
setIcon(<Home className='h-4 w-4' />);
} else if (pathname === '/app/explore') {
} else if (pathname.startsWith('/app/explore')) {
setIcon(<Compass className='h-4 w-4' />);
} else if (pathname === '/app/notifications') {
setIcon(<Bell className='h-4 w-4' />);
Expand Down
16 changes: 4 additions & 12 deletions client/components/app/Post/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default function PostList({ fetchPosts }) {
const [posts, setPosts] = useState([]);
const [offset, setOffset] = useState(10);
const [hasMorePost, setHasMorePost] = useState(true);
const [loading, setLoading] = useState(false);
const { toast } = useToast();

const handleDelete = (postId) => {
Expand Down Expand Up @@ -43,9 +42,7 @@ export default function PostList({ fetchPosts }) {

useEffect(() => {
const fetchInitialPosts = async () => {
setLoading(true);
const response = await fetchPosts(0);
setLoading(false);

if (!response) {
toast({
Expand All @@ -72,10 +69,7 @@ export default function PostList({ fetchPosts }) {

return (
<div className='flex flex-col gap-2'>
{loading && (
<LoaderCircle className='mt-3 w-4 h-4 animate-spin self-center' />
)}
{!loading && posts.length > 0 ? (
{posts.length > 0 ? (
<>
{posts.map((post) => (
<Post key={post.id} post={post} onDelete={handleDelete} />
Expand All @@ -87,11 +81,9 @@ export default function PostList({ fetchPosts }) {
)}
</>
) : (
!loading && (
<div className='flex flex-col items-center justify-center text-sm'>
buralar şimdilik sessiz.
</div>
)
<div className='flex flex-col items-center justify-center text-sm'>
buralar şimdilik sessiz.
</div>
)}
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions client/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const nextConfig = {
destination: '/app/settings/profile',
permanent: true,
},
{
source: '/app/explore',
destination: '/app/explore/posts',
permanent: true,
}
];
}
};
Expand Down

0 comments on commit c39b33b

Please sign in to comment.