Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
update
Ashish Viradiyaac6633d2ac4a
diff --git a/components/documents/document-card.tsx b/components/documents/document-card.tsxindex aa2a3f31..996a1372 100644--- a/components/documents/document-card.tsx+++ b/components/documents/document-card.tsx@@ -58,6 +58,9 @@ export default function DocumentsCard({isHovered,}: DocumentsCardProps) {const router = useRouter();+ const queryParams = router.query;+ const searchQuery = queryParams["search"];+ const sortQuery = queryParams["sort"];const { theme, systemTheme } = useTheme();const isLight =theme === "light" || (theme === "system" && systemTheme === "light");@@ -256,9 +259,9 @@ export default function DocumentsCard({</>) : null}</div>- {prismaDocument?.folder?.path ?+ {searchQuery || sortQuery ?<div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-muted-foreground relative z-10">- {getBreadcrumbPath(prismaDocument.folder.path).map(+ {getBreadcrumbPath(prismaDocument.folderList).map((segment, index) => (<pclassName="flex inset-2 items-center gap-x-1 truncate"diff --git a/lib/types.ts b/lib/types.tsindex 19bfeeb4..abc7c410 100644--- a/lib/types.ts+++ b/lib/types.ts@@ -35,6 +35,7 @@ export interface DocumentWithLinksAndLinkCountAndViewCount extends Document {name: string;path: string;}+ folderList: string[];}export interface DocumentWithVersion extends Document {diff --git a/lib/utils.ts b/lib/utils.tsindex d13b0104..72798f00 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -1,3 +1,4 @@+import slugify from "@sindresorhus/slugify";import { upload } from "@vercel/blob/client";import { Message } from "ai";import bcrypt from "bcryptjs";@@ -541,19 +542,18 @@ export function hexToRgb(hex: string) {export const trim = (u: unknown) => (typeof u === "string" ? u.trim() : u);-export const deSlugify = (slug: string) => {- return slug- .split('-')- // .map(word => word.charAt(0).toUpperCase() + word.slice(1))- .join(' ');-};--export const getBreadcrumbPath = (path: string, basePath = "documents/tree") => {- const segments = path.split("/").filter(Boolean); // Remove empty strings- let currentPath = basePath; // Start with base path-- return segments.map((segment) => {- currentPath += `/${segment}`; // Append current segment to path- return { name: deSlugify(segment), pathLink: currentPath };- });+export const getBreadcrumbPath = (path: string[]) => {+ const segments = path.filter(Boolean);+ let currentPath = "documents/tree";++ return [+ { name: "Home", pathLink: "/documents" },+ ...segments.map((segment, index) => {+ currentPath += `/${slugify(segment)}`;+ return {+ name: segment,+ pathLink: currentPath+ };+ })+ ];};\ No newline at end of filediff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.tsindex cffd0b19..8f2f104b 100644--- a/pages/api/teams/[teamId]/documents/index.ts+++ b/pages/api/teams/[teamId]/documents/index.ts@@ -111,10 +111,40 @@ export default async function handle(},});- let sortedDocuments = documents;+ let documentsWithFolderList = documents;++ if (query || sort) {+ documentsWithFolderList = await Promise.all(documents.map(async (doc) => {+ const folderNames = [];+ const pathSegments = doc.folder?.path?.split("/") || [];++ if (pathSegments.length > 0) {+ const folders = await prisma.folder.findMany({+ where: {+ teamId,+ path: {+ in: pathSegments.map((_, index) =>+ pathSegments.slice(0, index + 1).join("/")+ )+ }+ },+ select: {+ path: true,+ name: true,+ },+ orderBy: {+ path: 'asc'+ }+ });+ folderNames.push(...folders.map(f => f.name));+ }+ return { ...doc, folderList: folderNames };+ }));+ }+ // Sort after we have the complete listif (sort === "lastViewed") {- sortedDocuments = documents.sort((a, b) => {+ documentsWithFolderList = documentsWithFolderList.sort((a, b) => {const aLastView = a.views[0]?.viewedAt;const bLastView = b.views[0]?.viewedAt;@@ -126,12 +156,12 @@ export default async function handle(}if (sort === "name") {- sortedDocuments = documents.sort((a, b) =>+ documentsWithFolderList = documentsWithFolderList.sort((a, b) =>a.name.toLowerCase().localeCompare(b.name.toLowerCase()),);}- return res.status(200).json(sortedDocuments);+ return res.status(200).json(documentsWithFolderList);} catch (error) {errorhandler(error, res);}