Skip to content

Commit

Permalink
feat(occurrence/[occurrence_id]/page.tsx): add generateMetadata funct…
Browse files Browse the repository at this point in the history
…ion to set the page title to the occurrence message

fix(components/BookmarksTable.tsx): fix occurrence link href to use occurrence_id instead of occurrence.id
fix(lib/actions/occurrenceActions.ts): add error handling for session not found when creating or removing occurrence bookmarks
  • Loading branch information
masterkain committed May 28, 2023
1 parent ab075dc commit e42676e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
18 changes: 11 additions & 7 deletions app/occurrences/[occurrence_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ import classNames from '@/lib/classNames';
import { checkOccurrenceBookmarkExistence } from '@/lib/queries/occurrenceBookmarks';
import { getOccurrenceById } from '@/lib/queries/occurrences';
import type { Route } from 'next';
import { Metadata } from 'next';
import { getServerSession } from 'next-auth';
import Link from 'next/link';
import { FaCarCrash } from 'react-icons/fa';
import { SlCompass, SlGlobe, SlGraph, SlLink, SlList, SlUser, SlWrench } from 'react-icons/sl';

type OccurrenceTabKeys = 'backtrace' | 'context' | 'environment' | 'session' | 'params' | 'chart' | 'toolbox';

export default async function Occurrence({
params,
searchParams,
}: {
type ComponentProps = {
params: { occurrence_id: string };
searchParams: Record<string, string>;
}) {
searchParams: { [key: string]: string | undefined };
};
export async function generateMetadata({ params }: ComponentProps): Promise<Metadata> {
const occurrence = await getOccurrenceById(params.occurrence_id);
return { title: occurrence?.message };
}

export default async function Occurrence({ params, searchParams }: ComponentProps) {
const session = await getServerSession(authOptions);
const userId = session?.user?.id;
const occurrence = await getOccurrenceById(params.occurrence_id);
Expand Down Expand Up @@ -65,7 +69,7 @@ export default async function Occurrence({
},
{ name: occurrence.notice.kind, href: `/notices/${occurrence.notice_id}` as Route, current: false },
{
name: occurrence.message,
name: `${occurrence.message} (${occurrence.id})`,
href: `/occurrences/${occurrence.id}` as Route,
current: true,
},
Expand Down
2 changes: 1 addition & 1 deletion components/BookmarksTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function BookmarksTable({ searchQuery }: BookmarksTableProps) {
<div className="min-w-0 flex-auto">
<div className="flex items-center gap-x-3">
<h2 className="min-w-0 text-sm font-semibold leading-6 text-white">
<Link href={`/occurrences/${bookmark.occurrence.id}`} className="flex gap-x-2">
<Link href={`/occurrences/${bookmark.occurrence_id}`} className="flex gap-x-2">
<span className="truncate">{bookmark.occurrence.message}</span>
<span className="absolute inset-0" />
</Link>
Expand Down
14 changes: 10 additions & 4 deletions lib/actions/occurrenceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,36 @@ export async function performReplay(context: Context): Promise<string> {
// Function to create a bookmark for a user
export async function createOccurrenceBookmark(occurrenceId: string) {
const session = await getServerSession();
if (!session) {
throw new Error('Session not found');
}

await prisma.occurrenceBookmark.create({
data: {
user_id: session?.user?.id!,
user_id: session.user?.id!,
occurrence_id: occurrenceId,
},
});

revalidatePath('/bookmarks')
revalidatePath(`/occurrences/${occurrenceId}`)
revalidatePath('/bookmarks')
}

export async function removeOccurrenceBookmark(occurrenceId: string) {
const session = await getServerSession();
if (!session) {
throw new Error('Session not found');
}

await prisma.occurrenceBookmark.delete({
where: {
user_id_occurrence_id: {
user_id: session?.user?.id!,
user_id: session.user?.id!,
occurrence_id: occurrenceId,
},
},
});

revalidatePath('/bookmarks')
revalidatePath(`/occurrences/${occurrenceId}`)
revalidatePath('/bookmarks')
}

0 comments on commit e42676e

Please sign in to comment.