Skip to content

Commit

Permalink
update(aih): move list detail to root route
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtaholik committed Jan 10, 2025
1 parent 63f6560 commit 89ddfc8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 33 deletions.
23 changes: 18 additions & 5 deletions apps/ai-hero/src/app/(content)/[post]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Share } from '@/components/share'
import Spinner from '@/components/spinner'
import { courseBuilderAdapter } from '@/db'
import type { List } from '@/lib/lists'
import { getListForPost } from '@/lib/lists-query'
import { getAllLists, getListForPost } from '@/lib/lists-query'
import { type Post } from '@/lib/posts'
import { getAllPosts, getPost } from '@/lib/posts-query'
import { getPricingProps } from '@/lib/pricing-query'
Expand All @@ -31,6 +31,7 @@ import { Button } from '@coursebuilder/ui'
import { VideoPlayerOverlayProvider } from '@coursebuilder/ui/hooks/use-video-player-overlay'

import PostNextUpFromListPagination from '../_components/post-next-up-from-list-pagination'
import ListPage from '../lists/[slug]/_page'
import { PostPlayer } from '../posts/_components/post-player'
import { PostNewsletterCta } from '../posts/_components/post-video-subscribe-form'

Expand All @@ -41,11 +42,14 @@ type Props = {

export async function generateStaticParams() {
const posts = await getAllPosts()
const lists = await getAllLists()

return posts
.filter((post) => Boolean(post.fields?.slug))
.map((post) => ({
post: post.fields?.slug,
const resources = [...posts, ...lists]

return resources
.filter((resource) => Boolean(resource.fields?.slug))
.map((resource) => ({
post: resource.fields?.slug,
}))
}

Expand Down Expand Up @@ -147,6 +151,15 @@ export default async function PostPage(props: {
const params = await props.params
const post = await getPost(params.post)

if (!post) {
return (
<ListPage
params={{ slug: params.post } as any}
searchParams={searchParams as any}
/>
)
}

const cookieStore = await cookies()
const ckSubscriber = cookieStore.has(CK_SUBSCRIBER_KEY)
const { allowPurchase, pricingDataLoader, product, commerceProps } =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Used for root route /[post]

import * as React from 'react'
import { Suspense } from 'react'
import { type Metadata, type ResolvingMetadata } from 'next'
Expand Down Expand Up @@ -136,10 +138,10 @@ export default async function ListPage(props: {
{list.resources.map(({ resource }, i) => (
<li key={resource.id}>
<Link
className="hover:bg-muted flex items-center gap-3 px-2 py-2 transition"
className="hover:bg-muted flex items-center gap-3 px-2 py-2 font-medium transition"
href={`/${resource.fields.slug}`}
>
<small className="min-w-[2ch] text-right font-mono text-xs opacity-60">
<small className="min-w-[2ch] text-right font-mono text-xs font-normal opacity-60">
{i + 1}
</small>
{resource.fields.title}
Expand Down
55 changes: 29 additions & 26 deletions apps/ai-hero/src/app/(content)/lists/_components/lists-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import Link from 'next/link'
import type { List } from '@/lib/lists'
import { deleteList } from '@/lib/lists-query'
import { Trash } from 'lucide-react'
import { Edit3, Trash } from 'lucide-react'

import {
Alert,
Expand Down Expand Up @@ -36,19 +36,15 @@ export function ListsTable({
<TableHead>Description</TableHead>
<TableHead>Type</TableHead>
<TableHead>Resources</TableHead>
<TableHead>Actions</TableHead>
{canCreateContent && <TableHead>Actions</TableHead>}
</TableRow>
</TableHeader>
<TableBody>
{lists.map((list) => (
<TableRow key={list.id}>
<TableCell>
<Link
href={
canCreateContent
? `/lists/${list.fields.slug}/edit`
: `/lists/${list.fields.slug}`
}
href={`/${list.fields.slug}`}
className="text-primary text-lg font-medium hover:underline"
>
{list.fields.title}
Expand All @@ -59,25 +55,32 @@ export function ListsTable({
</TableCell>
<TableCell>{list.fields.type}</TableCell>
<TableCell>{list.resources?.length || 0}</TableCell>
<TableCell>
<Button
title={
list.resources.length > 0
? 'Delete list'
: 'Must be empty to delete'
}
disabled={list.resources.length > 0}
size="icon"
variant="outline"
onClick={async () => {
await deleteList(list.id).catch((e) => {
setError(e)
})
}}
>
<Trash className="h-3 w-3" />
</Button>
</TableCell>
{canCreateContent && (
<TableCell className="flex gap-2">
<Button asChild title="Edit" size="icon" variant="outline">
<Link href={`/lists/${list.fields.slug}/edit`}>
<Edit3 className="h-3 w-3" />
</Link>
</Button>
<Button
title={
list.resources.length > 0
? 'Delete'
: 'Must be empty to delete'
}
disabled={list.resources.length > 0}
size="icon"
variant="outline"
onClick={async () => {
await deleteList(list.id).catch((e) => {
setError(e)
})
}}
>
<Trash className="h-3 w-3" />
</Button>
</TableCell>
)}
</TableRow>
))}
{lists.length === 0 && (
Expand Down

0 comments on commit 89ddfc8

Please sign in to comment.