Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/(loggedInRoutes)/admin/checklist/[uuid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default async function AdminChecklistPage(props: AdminChecklistPageProps)
: [];

const metadata = {
id: checklist.id,
id: checklist.slug,
uuid: checklist.uuid,
title: checklist.title,
category: checklist.category || "Uncategorized",
Expand Down
2 changes: 1 addition & 1 deletion app/(loggedInRoutes)/admin/note/[uuid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default async function AdminNotePage(props: AdminNotePageProps) {
: [];

const metadata = {
id: note.id,
id: note.slug,
uuid: note.uuid,
title: note.title,
category: note.category || "Uncategorized",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,42 @@ import { sanitizeUserForClient } from "@/app/_utils/user-sanitize-utils";

interface ChecklistPageProps {
params: Promise<{
categoryPath: string[];
user: string;
uuid: string;
}>;
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}

export const dynamic = "force-dynamic";

export async function generateMetadata(props: ChecklistPageProps): Promise<Metadata> {
const params = await props.params;
const { categoryPath } = params;
const id = decodeId(categoryPath[categoryPath.length - 1]);
const encodedCategoryPath = categoryPath.slice(0, -1).join("/");
const category =
categoryPath.length === 1
? "Uncategorized"
: decodeCategoryPath(encodedCategoryPath);

return getMedatadaTitle(Modes.CHECKLISTS, id, category);
const { user, uuid } = params;
return getMedatadaTitle(Modes.CHECKLISTS, decodeId(uuid), decodeURIComponent(user));
}

export default async function ChecklistPage(props: ChecklistPageProps) {
const params = await props.params;
const { categoryPath } = params;
const id = decodeId(categoryPath[categoryPath.length - 1]);
const encodedCategoryPath = categoryPath.slice(0, -1).join("/");
const category =
categoryPath.length === 1
? "Uncategorized"
: decodeCategoryPath(encodedCategoryPath);
const searchParams = await props.searchParams;
const { user: ownerUsername, uuid } = params;
const id = decodeId(uuid);
const owner = decodeURIComponent(ownerUsername);

const categoryFallbackRaw = searchParams?.c;
const categoryFallback = Array.isArray(categoryFallbackRaw)
? categoryFallbackRaw[0]
: categoryFallbackRaw;

const userRecord = await getCurrentUser();
const username = userRecord?.username || "";
const hasContentAccess = await canAccessAllContent();

const categoriesResult = await getCategories(Modes.CHECKLISTS);

let checklist = await getListById(id, username, category);
let checklist = await getListById(id, owner, username, false, categoryFallback);

if (!checklist && hasContentAccess) {
checklist = await getListById(id, undefined, category);
checklist = await getListById(id, owner, undefined, false, categoryFallback);
}

if (!checklist) {
Expand All @@ -63,7 +61,7 @@ export default async function ChecklistPage(props: ChecklistPageProps) {
: [];

const metadata = {
id: checklist.id,
id: checklist.slug,
uuid: checklist.uuid,
title: checklist.title,
category: checklist.category || "Uncategorized",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,32 @@ import { MetadataProvider } from "@/app/_providers/MetadataProvider";

interface NotePageProps {
params: Promise<{
categoryPath: string[];
user: string;
uuid: string;
}>;
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}

export const dynamic = "force-dynamic";

export async function generateMetadata(props: NotePageProps): Promise<Metadata> {
const params = await props.params;
const { categoryPath } = params;
const id = decodeId(categoryPath[categoryPath.length - 1]);
const encodedCategoryPath = categoryPath.slice(0, -1).join("/");
const category =
categoryPath.length === 1
? "Uncategorized"
: decodeCategoryPath(encodedCategoryPath);

return getMedatadaTitle(Modes.NOTES, id, category);
const { user, uuid } = params;
return getMedatadaTitle(Modes.NOTES, decodeId(uuid), decodeURIComponent(user));
}

export default async function NotePage(props: NotePageProps) {
const params = await props.params;
const { categoryPath } = params;
const id = decodeId(categoryPath[categoryPath.length - 1]);
const encodedCategoryPath = categoryPath.slice(0, -1).join("/");
const category =
categoryPath.length === 1
? "Uncategorized"
: decodeCategoryPath(encodedCategoryPath);
const searchParams = await props.searchParams;
const { user: ownerUsername, uuid } = params;
const id = decodeId(uuid);
const owner = decodeURIComponent(ownerUsername);

const categoryFallbackRaw = searchParams?.c;
const categoryFallback = Array.isArray(categoryFallbackRaw)
? categoryFallbackRaw[0]
: categoryFallbackRaw;

const user = await getCurrentUser();
const username = user?.username || "";
const hasContentAccess = await canAccessAllContent();
Expand All @@ -54,10 +52,10 @@ export default async function NotePage(props: NotePageProps) {

const categoriesResult = await getCategories(Modes.NOTES);

let note = await getNoteById(id, category, username);
let note = await getNoteById(id, owner, username, false, categoryFallback);

if (!note && hasContentAccess) {
note = await getNoteById(id, category);
note = await getNoteById(id, owner, undefined, false, categoryFallback);
}

if (!note) {
Expand All @@ -70,7 +68,7 @@ export default async function NotePage(props: NotePageProps) {
: [];

const metadata = {
id: note.id,
id: note.slug,
uuid: note.uuid,
title: note.title,
category: note.category || "Uncategorized",
Expand Down
4 changes: 2 additions & 2 deletions app/(loggedInRoutes)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export default async function HomePage() {
<HomeClient
initialLists={lists as Checklist[]}
initialCategories={categories}
initialDocs={notes as Note[]}
initialDocsCategories={notesCategories}
initialNotes={notes as Note[]}
initialNotesCategories={notesCategories}
user={userForClient}
/>
);
Expand Down
26 changes: 13 additions & 13 deletions app/(loggedInRoutes)/settings/admin/content/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import { canAccessAllContent } from "@/app/_server/actions/users";
import { notFound } from "next/navigation";

export default async function AdminContentPage() {
const hasAccess = await canAccessAllContent();
const hasAccess = await canAccessAllContent();

if (!hasAccess) {
return notFound();
}
if (!hasAccess) {
return notFound();
}

const [usersData, listsData, docsData] = await Promise.all([
readJsonFile(USERS_FILE),
getAllLists(),
getAllNotes(),
]);
const [usersData, listsData, docsData] = await Promise.all([
readJsonFile(USERS_FILE),
getAllLists(),
getAllNotes(),
]);

const users = usersData;
const allLists = listsData.success && listsData.data ? listsData.data : [];
const allDocs = docsData.success && docsData.data ? docsData.data : [];
const users = usersData;
const allLists = listsData.success && listsData.data ? listsData.data : [];
const allNotes = docsData.success && docsData.data ? docsData.data : [];

return <AdminContent allLists={allLists} allDocs={allDocs} users={users} />;
return <AdminContent allLists={allLists} allNotes={allNotes} users={users} />;
}
38 changes: 19 additions & 19 deletions app/(loggedInRoutes)/settings/admin/overview/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import { getAllLists } from "@/app/_server/actions/checklist";
import { getAllNotes } from "@/app/_server/actions/note";

export default async function AdminOverviewPage() {
const admin = await isAdmin();
const admin = await isAdmin();

if (!admin) {
return notFound();
}
if (!admin) {
return notFound();
}

const [usersData, listsData, docsData] = await Promise.all([
readJsonFile(USERS_FILE),
getAllLists(),
getAllNotes(),
]);
const [usersData, listsData, docsData] = await Promise.all([
readJsonFile(USERS_FILE),
getAllLists(),
getAllNotes(),
]);

const users = usersData;
const allLists = listsData.success && listsData.data ? listsData.data : [];
const allDocs = docsData.success && docsData.data ? docsData.data : [];
const users = usersData;
const allLists = listsData.success && listsData.data ? listsData.data : [];
const allNotes = docsData.success && docsData.data ? docsData.data : [];

const stats = {
totalUsers: users.length,
totalChecklists: allLists.length,
totalNotes: allDocs.length,
adminUsers: users.filter((u: any) => u.isAdmin).length,
};
const stats = {
totalUsers: users.length,
totalChecklists: allLists.length,
totalNotes: allNotes.length,
adminUsers: users.filter((u: any) => u.isAdmin).length,
};

return <AdminOverview stats={stats} />;
return <AdminOverview stats={stats} />;
}
42 changes: 21 additions & 21 deletions app/(loggedInRoutes)/settings/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import { isAdmin, getUsername } from "@/app/_server/actions/users";
import { notFound } from "next/navigation";

export default async function AdminUsersPage() {
const admin = await isAdmin();
const username = await getUsername();
const admin = await isAdmin();
const username = await getUsername();

if (!admin) {
return notFound();
}
if (!admin) {
return notFound();
}

const [usersData, listsData, docsData] = await Promise.all([
readJsonFile(USERS_FILE),
getAllLists(),
getAllNotes(),
]);
const [usersData, listsData, docsData] = await Promise.all([
readJsonFile(USERS_FILE),
getAllLists(),
getAllNotes(),
]);

const users = usersData;
const allLists = listsData.success && listsData.data ? listsData.data : [];
const allDocs = docsData.success && docsData.data ? docsData.data : [];
const users = usersData;
const allLists = listsData.success && listsData.data ? listsData.data : [];
const allNotes = docsData.success && docsData.data ? docsData.data : [];

return (
<AdminUsersClient
initialUsers={users}
initialLists={allLists}
initialDocs={allDocs}
username={username}
/>
);
return (
<AdminUsersClient
initialUsers={users}
initialLists={allLists}
initialNotes={allNotes}
username={username}
/>
);
}
Loading
Loading