-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: add user profile * refactor: make navbar visible in all auth cases * refactor: layout and route nits, and place back favicon as vite public asset * tests: add user-feed acess minimal browser specs * fix: solve routing issue * style: more nits * fix: include favicon in bundle
- Loading branch information
1 parent
be0943a
commit 1a95208
Showing
19 changed files
with
306 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import User from '#models/user'; | ||
import PostsService from '#services/posts_service'; | ||
import { inject } from '@adonisjs/core'; | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
|
||
@inject() | ||
export default class UsersController { | ||
|
||
constructor(public readonly service: PostsService) { } | ||
|
||
async show(ctx: HttpContext) { | ||
const profileId = ctx.params.id; | ||
const page = ctx.request.qs().page || 1 | ||
const posts = await this.service.findMany(profileId, { page }) | ||
const profile = await User.find(profileId); | ||
return ctx.inertia.render('users/show', { posts, profile }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { useEffect, useMemo, useState } from 'react' | ||
import { router } from '@inertiajs/react' | ||
import { useToast } from '@/components/ui/use-toast' | ||
import PostCard from '@/components/posts/post-card' | ||
import { useIntersectionObserver } from '@/hooks/use-intersection-observer' | ||
import { Loader2 } from 'lucide-react' | ||
import { ModelObject } from '@adonisjs/lucid/types/model' | ||
|
||
export default function FeedList({ | ||
url, | ||
posts, | ||
currentUser, | ||
}: { | ||
url: string | ||
posts: { | ||
meta: any | ||
data: ModelObject[] | ||
} | ||
currentUser: { | ||
[x: string]: any | ||
} | null | ||
}) { | ||
const [allPosts, setAllPosts] = useState(posts?.data) | ||
const [meta, setMeta] = useState(posts.meta) | ||
|
||
const { toast } = useToast() | ||
|
||
const { isIntersecting, ref } = useIntersectionObserver({ | ||
threshold: 0.5, | ||
}) | ||
|
||
function loadMore() { | ||
router.get( | ||
`${url}${meta.nextPageUrl}`, | ||
{}, | ||
{ | ||
preserveState: true, | ||
preserveScroll: true, | ||
onSuccess: () => { | ||
setAllPosts((prev) => [...(prev ?? []), ...posts.data]) | ||
setMeta(posts.meta) | ||
}, | ||
onError: () => { | ||
toast({ title: 'Error loading next page.' }) | ||
}, | ||
} | ||
) | ||
} | ||
|
||
const hasMorePosts = useMemo(() => !!meta?.nextPageUrl, [meta]) | ||
|
||
useEffect(() => { | ||
if (isIntersecting) loadMore() | ||
}, [isIntersecting]) | ||
|
||
return ( | ||
<div className="feed-list w-full"> | ||
{!allPosts ? ( | ||
<Loader2 className="h-5 w-5 mr-2 animate-spin text-muted" /> | ||
) : ( | ||
allPosts?.map((post, index) => <PostCard user={currentUser} post={post} key={index} />) | ||
)} | ||
<div className="flex justify-center py-5 w-full min-w-full"> | ||
{posts?.data?.length > 0 ? ( | ||
<> | ||
{hasMorePosts ? ( | ||
<p ref={ref} className="text-sm text-gray-600 self-center cursor-pointer"> | ||
fetch more around here | ||
</p> | ||
) : ( | ||
<p className="text-sm text-gray-600 self-center">Go touch grass outside.</p> | ||
)} | ||
</> | ||
) : ( | ||
<div className="flex w-full hn-screen items-center justify-center"> | ||
<p className="text-sm text-gray-600 self-center">Nothing to see here. 🍃</p> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.