diff --git a/config/inertia.ts b/config/inertia.ts index d3957c5..2284973 100644 --- a/config/inertia.ts +++ b/config/inertia.ts @@ -1,5 +1,6 @@ import { UserResponse } from '#interfaces/user' import { UserService } from '#services/user_service' +import env from '#start/env' import { defineConfig } from '@adonisjs/inertia' import type { InferSharedProps } from '@adonisjs/inertia/types' @@ -24,6 +25,7 @@ const inertiaConfig = defineConfig({ }, queryParams: (ctx) => ctx.request.qs(), errors: (ctx) => ctx.session?.flashMessages.get('errors'), + domain: () => env.get('PRODUCTION_URL'), }, /** diff --git a/inertia/components/generic/head_og.tsx b/inertia/components/generic/head_og.tsx new file mode 100644 index 0000000..41413d1 --- /dev/null +++ b/inertia/components/generic/head_og.tsx @@ -0,0 +1,27 @@ +import { Head, usePage } from '@inertiajs/react' +import socialAdonisLogo from '../../../public/assets/images/thumbnail.png' + +interface HeadOGProps { + title: string + description: string + url: string + image?: string +} + +export default function HeadOG({ title, description, image, url }: HeadOGProps) { + const props = usePage().props + + const domain = props.domain + + return ( + + + + + + + + + + ) +} diff --git a/inertia/components/users/nav.tsx b/inertia/components/users/nav.tsx index c5d9346..706d398 100644 --- a/inertia/components/users/nav.tsx +++ b/inertia/components/users/nav.tsx @@ -87,7 +87,7 @@ export default function UserNavBar({ user }: { user: UserResponse | null }) { > Settings diff --git a/inertia/pages/feed.tsx b/inertia/pages/feed.tsx index 775828e..268d4b4 100644 --- a/inertia/pages/feed.tsx +++ b/inertia/pages/feed.tsx @@ -1,14 +1,18 @@ import { route } from '@izzyjs/route/client' -import { Head } from '@inertiajs/react' import { CreatePost } from '@/components/posts/create' import FeedList from '@/components/posts/feed_list' import type { InferPageProps } from '@adonisjs/inertia/types' import type FeedController from '#controllers/feed_controller' +import HeadOG from '@/components/generic/head_og' export default function Feed({ posts, user }: InferPageProps) { return ( <> - + {user && (
diff --git a/inertia/pages/home.tsx b/inertia/pages/home.tsx index e873667..ca258a0 100644 --- a/inertia/pages/home.tsx +++ b/inertia/pages/home.tsx @@ -1,12 +1,17 @@ -import { Head, Link } from '@inertiajs/react' +import { Link } from '@inertiajs/react' import { route } from '@izzyjs/route/client' import { Button } from '@/components/ui/button' import AdonisLogo from '@/components/svg/logo' +import HeadOG from '@/components/generic/head_og' export default function Home() { return ( <> - +
Landing page
diff --git a/inertia/pages/posts/show.tsx b/inertia/pages/posts/show.tsx index c49c605..8925d28 100644 --- a/inertia/pages/posts/show.tsx +++ b/inertia/pages/posts/show.tsx @@ -1,10 +1,11 @@ import PostsController from '#controllers/posts_controller' import { PostStatus } from '#enums/post' +import HeadOG from '@/components/generic/head_og' import InfoPanel from '@/components/generic/info_panel' import PostCard from '@/components/posts/post_card' import { Button } from '@/components/ui/button' import { InferPageProps } from '@adonisjs/inertia/types' -import { Head, router } from '@inertiajs/react' +import { router } from '@inertiajs/react' import { route } from '@izzyjs/route/client' import { MoveLeft } from 'lucide-react' @@ -12,7 +13,11 @@ export default function Show({ post, user }: InferPagePropsloading... return ( <> - +
- +
diff --git a/inertia/pages/sign_up.tsx b/inertia/pages/sign_up.tsx index 48290a6..4472c81 100644 --- a/inertia/pages/sign_up.tsx +++ b/inertia/pages/sign_up.tsx @@ -1,5 +1,6 @@ import { useEffect } from 'react' -import { Head, Link, useForm } from '@inertiajs/react' +import { Link, useForm } from '@inertiajs/react' +import HeadOG from '@/components/generic/head_og' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Input } from '@/components/ui/input' @@ -31,7 +32,11 @@ export default function SignUp() { return ( <> - +
diff --git a/inertia/pages/users/settings.tsx b/inertia/pages/users/settings.tsx index fdaa232..d61136d 100644 --- a/inertia/pages/users/settings.tsx +++ b/inertia/pages/users/settings.tsx @@ -1,5 +1,6 @@ import UsersController from '#controllers/users_controller' import { UserResponse } from '#interfaces/user' +import HeadOG from '@/components/generic/head_og' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' @@ -8,7 +9,7 @@ import { Label } from '@/components/ui/label' import { useToast } from '@/components/ui/use_toast' import { cn } from '@/lib/utils' import { InferPageProps } from '@adonisjs/inertia/types' -import { Head, useForm, usePage } from '@inertiajs/react' +import { useForm, usePage } from '@inertiajs/react' import { route } from '@izzyjs/route/client' import { AtSign, Upload } from 'lucide-react' import { ChangeEvent, useEffect, useRef, useState } from 'react' @@ -93,7 +94,11 @@ export default function UserSettings({ return ( <> - +
diff --git a/inertia/pages/users/show.tsx b/inertia/pages/users/show.tsx index b6ec405..318f4cc 100644 --- a/inertia/pages/users/show.tsx +++ b/inertia/pages/users/show.tsx @@ -1,10 +1,10 @@ import { useState } from 'react' import FeedController from '#controllers/feed_controller' +import HeadOG from '@/components/generic/head_og' import FeedList from '@/components/posts/feed_list' import { Card, CardContent } from '@/components/ui/card' import { InferPageProps } from '@adonisjs/inertia/types' import { lightFormat } from 'date-fns' -import { Head } from '@inertiajs/react' import { BadgeCheck, CalendarHeart, FilePen } from 'lucide-react' import { CreatePost } from '@/components/posts/create' import { UserResponse } from '#interfaces/user' @@ -68,7 +68,18 @@ export default function Show({ user, posts, profile }: InferPagePropsLoading.. return ( <> - +
diff --git a/public/assets/images/thumbnail.png b/public/assets/images/thumbnail.png new file mode 100644 index 0000000..4501791 Binary files /dev/null and b/public/assets/images/thumbnail.png differ diff --git a/start/routes.ts b/start/routes.ts index e4e5f0a..b57aade 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -29,6 +29,11 @@ router .group(() => { router.on('/').renderInertia('home').as('home.show') router.get('/feed', [FeedController, 'index']).as('feed.show') + router + .group(() => { + router.get(':id', [FeedController, 'show']).as('users.show') + }) + .prefix('users') }) .use(middleware.guest()) @@ -66,13 +71,13 @@ router router .group(() => { router.get('/', [UsersController, 'index']).as('users.index') - router.get(':id', [FeedController, 'show']).as('users.show') // TODO: Make public, and contextualize `ctx.auth.authenticate` via middleware. - router.get(':id/settings', [UsersController, 'show']).as('settings.show') router.patch(':id', [UsersController, 'update']).as('users.update') router.delete(':id', [UsersController, 'destroy']).as('users.destroy') }) .prefix('users') + router.get('settings', [UsersController, 'show']).as('settings.show') + router .group(() => { router.post('/', [PostsController, 'store']).as('posts.store') diff --git a/tests/browser/admin_post_report.spec.ts b/tests/browser/admin_post_report.spec.ts index eb5e6d8..859dc12 100644 --- a/tests/browser/admin_post_report.spec.ts +++ b/tests/browser/admin_post_report.spec.ts @@ -1,11 +1,11 @@ import { UserFactory } from '#database/factories/user_factory' import { PostReportReason, PostReportStatus } from '#enums/post' import testUtils from '@adonisjs/core/services/test_utils' +import { route } from '@izzyjs/route/client' import { test } from '@japa/runner' test.group('Admin post report', (group) => { - // FIX-ME: Izzy - const url = '/admin/posts/reports' + const url = route('admin_posts_reports.index').path group.each.setup(() => testUtils.db().truncate()) diff --git a/tests/browser/pages/feed.spec.ts b/tests/browser/pages/feed.spec.ts index c574721..8ba4667 100644 --- a/tests/browser/pages/feed.spec.ts +++ b/tests/browser/pages/feed.spec.ts @@ -1,12 +1,13 @@ import { UserFactory } from '#database/factories/user_factory' import testUtils from '@adonisjs/core/services/test_utils' +import { route } from '@izzyjs/route/client' import { test } from '@japa/runner' test.group('Acessing feed', (group) => { group.each.setup(() => testUtils.db().truncate()) test('Fails to access the feed without being authenticated', async ({ visit }) => { - const page = await visit('/feed') + const page = await visit(route('feed.show').path) await page.assertTextContains('body', 'Sign in') }) @@ -14,7 +15,7 @@ test.group('Acessing feed', (group) => { const user = await UserFactory.create() const created = await UserFactory.with('posts', 8).create() await browserContext.loginAs(user) - const page = await visit('/feed') + const page = await visit(route('feed.show').path) const locator = page.locator('.feed-list > article > .post-content') await page.assertElementsText( locator, @@ -27,7 +28,7 @@ test.group('Acessing feed', (group) => { await UserFactory.with('posts', 8).create() await browserContext.loginAs(user) - const page = await visit('/feed') + const page = await visit(route('feed.show').path) await page.locator('button.create-post').click() const postContent = 'Lets get dat bread! 🍞' @@ -42,7 +43,13 @@ test.group('Acessing feed', (group) => { await UserFactory.with('posts', 8).create() await browserContext.loginAs(user) - const page = await visit(`/posts/${user.posts[0].id}`) + const page = await visit( + route('posts.show', { + params: { + id: user.posts[0].id, + }, + }).path + ) await page.locator('button.trigger-user-post-actions').click() const updateButton = page.locator('button.update-post-trigger') @@ -59,7 +66,13 @@ test.group('Acessing feed', (group) => { await UserFactory.with('posts', 8).create() await browserContext.loginAs(user) - const page = await visit(`/posts/${user.posts[0].id}`) + const page = await visit( + route('posts.show', { + params: { + id: user.posts[0].id, + }, + }).path + ) await page.locator('button.trigger-user-post-actions').click() const deleteButton = page.locator('button.delete-post-trigger') @@ -75,7 +88,13 @@ test.group('Acessing feed', (group) => { const user = await UserFactory.with('posts', 1).create() const otherUser = await UserFactory.with('posts', 8).create() await browserContext.loginAs(user) - const page = await visit(`/posts/${otherUser.posts[0].id}`) + const page = await visit( + route('posts.show', { + params: { + id: otherUser.posts[0].id, + }, + }).path + ) await page.locator('button.trigger-user-post-actions').click() const updateAction = page.locator('button.update-post-trigger') const deleteAction = page.locator('button.delete-post-trigger') @@ -88,7 +107,13 @@ test.group('Acessing feed', (group) => { const otherUser = await UserFactory.with('posts', 8).create() await browserContext.loginAs(user) - const page = await visit(`/posts/${otherUser.posts[0].id}`) + const page = await visit( + route('posts.show', { + params: { + id: otherUser.posts[0].id, + }, + }).path + ) const reactButton = page.locator('button.trigger-user-post-react') await reactButton.hover() diff --git a/tests/browser/pages/user_feed.spec.ts b/tests/browser/pages/user_feed.spec.ts index ae891a2..9828eb7 100644 --- a/tests/browser/pages/user_feed.spec.ts +++ b/tests/browser/pages/user_feed.spec.ts @@ -1,5 +1,6 @@ import { UserFactory } from '#database/factories/user_factory' import testUtils from '@adonisjs/core/services/test_utils' +import { route } from '@izzyjs/route/client' import { test } from '@japa/runner' test.group('Acessing user profile feed', (group) => { @@ -7,7 +8,13 @@ test.group('Acessing user profile feed', (group) => { test('Fails to access the user profile feed without being authenticated', async ({ visit }) => { const user = await UserFactory.create() - const page = await visit(`/users/${user.id}`) + const page = await visit( + route('users.show', { + params: { + id: user.id, + }, + }).path + ) await page.assertTextContains('body', 'Sign in') }) @@ -17,7 +24,13 @@ test.group('Acessing user profile feed', (group) => { }) => { const user = await UserFactory.with('posts', 2).create() await browserContext.withGuard('web').loginAs(user) - const page = await visit(`/users/${user.id}`) + const page = await visit( + route('users.show', { + params: { + id: user.id, + }, + }).path + ) const locator = page.getByText('Total posts').first() await page.assertText(locator, `Total posts ${user.posts.length}`) }) @@ -29,7 +42,13 @@ test.group('Acessing user profile feed', (group) => { const user = await UserFactory.with('posts', 2).create() const otherUser = await UserFactory.with('posts', 8).create() await browserContext.loginAs(user) - const page = await visit(`/users/${otherUser.id}`) + const page = await visit( + route('users.show', { + params: { + id: otherUser.id, + }, + }).path + ) const locator = page.getByText('Total posts').first() await page.assertText(locator, `Total posts ${otherUser.posts.length}`) }) diff --git a/tests/browser/post_report.spec.ts b/tests/browser/post_report.spec.ts index 27ddb5e..a6f663e 100644 --- a/tests/browser/post_report.spec.ts +++ b/tests/browser/post_report.spec.ts @@ -2,11 +2,11 @@ import { UserFactory } from '#database/factories/user_factory' import User from '#models/user' import testUtils from '@adonisjs/core/services/test_utils' import { faker } from '@faker-js/faker' +import { route } from '@izzyjs/route/client' import { test } from '@japa/runner' test.group('Post report', (group) => { let user: User | null = null - const postShow = '/posts/:id' group.each.setup(async () => { await testUtils.db().truncate() @@ -16,10 +16,9 @@ test.group('Post report', (group) => { test('Successfuly creates a post report', async ({ browserContext, visit }) => { const authUser = user! const otherUser = await UserFactory.with('posts', 1).create() - const url = postShow.replace(':id', otherUser.posts[0].id) await browserContext.loginAs(authUser) - const page = await visit(url) + const page = await visit(route('posts.show', { params: { id: otherUser.posts[0].id } }).path) await page.locator('button.trigger-user-post-actions').click() await page.locator('button.report-post-trigger').click() await page.locator('button.select-reason').click() // FIX-ME: Review these tag classes. Too cumbersome. @@ -39,10 +38,11 @@ test.group('Post report', (group) => { }) ) ).create() - const url = postShow.replace(':id', userPostReport.posts[0].id) await browserContext.loginAs(authUser) - const page = await visit(url) + const page = await visit( + route('posts.show', { params: { id: userPostReport.posts[0].id } }).path + ) await page.locator('button.trigger-user-post-actions').click() await page.locator('button.report-post-trigger').click() await page.assertSelectedOptions('select', [userPostReport.posts[0].reports[0].reason]) diff --git a/tests/browser/user/settings.spec.ts b/tests/browser/user/settings.spec.ts index c5d4109..294dd09 100644 --- a/tests/browser/user/settings.spec.ts +++ b/tests/browser/user/settings.spec.ts @@ -4,16 +4,16 @@ import User from '#models/user' import testUtils from '@adonisjs/core/services/test_utils' import { InferPageProps, SharedProps } from '@adonisjs/inertia/types' import { faker } from '@faker-js/faker' +import { route } from '@izzyjs/route/client' import { test } from '@japa/runner' test.group('User settings', (group) => { let user: User | null = null - let url = '/users/:id/settings' + let url = route('settings.show').path group.each.setup(async () => { await testUtils.db().truncate() user = await UserFactory.create() - url = url.replace(':id', user.id) }) test('Sucessfully updates profile', async ({ visit, browserContext, assert }) => {