Some checks are pending
E2E / Playwright e2e (push) Waiting to run
- Introduced turbopack alias for canvas in next.config.mjs. - Updated package.json scripts for development and branding tasks. - Added new dependencies for Tiptap extensions. - Implemented new demo layouts for agenda, contacts, drive, and mail applications. - Enhanced globals.css for improved theming and splash screen animations. - Added OAuth callback handling for drive mounts. - Updated layout components to integrate new demo shells and improve structure.
118 lines
3.3 KiB
TypeScript
118 lines
3.3 KiB
TypeScript
import {
|
|
DEMO_DRIVE_FILES,
|
|
DEMO_DRIVE_RECENT_IDS,
|
|
DEMO_DRIVE_SHARED,
|
|
DEMO_DRIVE_STARRED_IDS,
|
|
DEMO_DRIVE_TRASH,
|
|
} from "@/components/demo/demo-drive-data"
|
|
import type { DriveFileInfo, DriveListResponse } from "@/lib/api/types"
|
|
|
|
function normalizeFolderPath(path: string): string {
|
|
if (!path || path === "/") return "/"
|
|
return path.startsWith("/") ? path.replace(/\/+$/, "") : `/${path.replace(/\/+$/, "")}`
|
|
}
|
|
|
|
function parentPath(path: string): string {
|
|
const normalized = path.replace(/\/+$/, "")
|
|
const idx = normalized.lastIndexOf("/")
|
|
if (idx <= 0) return "/"
|
|
return normalized.slice(0, idx)
|
|
}
|
|
|
|
function listChildren(files: DriveFileInfo[], folderPath: string): DriveFileInfo[] {
|
|
const folder = normalizeFolderPath(folderPath)
|
|
return files.filter((f) => {
|
|
if (f.type === "directory") {
|
|
if (folder === "/") return f.path.split("/").length === 2
|
|
return parentPath(f.path) === folder
|
|
}
|
|
return parentPath(f.path) === folder
|
|
})
|
|
}
|
|
|
|
function paginate(
|
|
items: DriveFileInfo[],
|
|
page: number,
|
|
pageSize = 50
|
|
): DriveListResponse {
|
|
const start = (page - 1) * pageSize
|
|
const slice = items.slice(start, start + pageSize)
|
|
return {
|
|
files: slice,
|
|
pagination: { page, page_size: pageSize, total: items.length },
|
|
}
|
|
}
|
|
|
|
export function listDemoDriveFiles(
|
|
files: DriveFileInfo[],
|
|
folderPath: string,
|
|
page: number
|
|
): DriveListResponse {
|
|
const children = listChildren(files, folderPath)
|
|
return paginate(children, page)
|
|
}
|
|
|
|
export function listDemoDriveRecent(files: DriveFileInfo[]): DriveListResponse {
|
|
const byId = new Map(files.map((f) => [f.file_id, f]))
|
|
const recent = DEMO_DRIVE_RECENT_IDS
|
|
.map((id) => byId.get(id))
|
|
.filter((f): f is DriveFileInfo => Boolean(f))
|
|
return { files: recent, pagination: { page: 1, page_size: 50, total: recent.length } }
|
|
}
|
|
|
|
export function listDemoDriveStarred(
|
|
files: DriveFileInfo[],
|
|
folderPath: string
|
|
): DriveListResponse {
|
|
const folder = normalizeFolderPath(folderPath)
|
|
const starred = files.filter(
|
|
(f) =>
|
|
f.is_favorite &&
|
|
(folder === "/" ? true : f.path.startsWith(folder === "/" ? "" : folder + "/"))
|
|
)
|
|
return { files: starred, pagination: { page: 1, page_size: 50, total: starred.length } }
|
|
}
|
|
|
|
export function listDemoDriveTrash(): DriveListResponse {
|
|
return {
|
|
files: [...DEMO_DRIVE_TRASH],
|
|
pagination: { page: 1, page_size: 50, total: DEMO_DRIVE_TRASH.length },
|
|
}
|
|
}
|
|
|
|
export function listDemoDriveShared(): DriveListResponse {
|
|
return {
|
|
files: [...DEMO_DRIVE_SHARED],
|
|
pagination: { page: 1, page_size: 50, total: DEMO_DRIVE_SHARED.length },
|
|
}
|
|
}
|
|
|
|
export function searchDemoDriveFiles(
|
|
files: DriveFileInfo[],
|
|
query: string,
|
|
scope: string,
|
|
folderPath: string,
|
|
page: number
|
|
): DriveListResponse {
|
|
const q = query.trim().toLowerCase()
|
|
let pool = files
|
|
if (scope === "folder") {
|
|
const folder = normalizeFolderPath(folderPath)
|
|
pool = files.filter(
|
|
(f) => f.path === folder || f.path.startsWith(folder === "/" ? "/" : folder + "/")
|
|
)
|
|
}
|
|
const matched = pool.filter((f) => {
|
|
if (!q) return false
|
|
return (
|
|
f.name.toLowerCase().includes(q) ||
|
|
f.path.toLowerCase().includes(q)
|
|
)
|
|
})
|
|
return paginate(matched, page)
|
|
}
|
|
|
|
export function createInitialDemoDriveFiles(): DriveFileInfo[] {
|
|
return [...DEMO_DRIVE_FILES]
|
|
}
|