- Updated .env.example to include configuration for OnlyOffice Document Server. - Modified the workspace configuration to remove the drive-suite path. - Adjusted TypeScript environment imports for consistency. - Enhanced Next.js configuration to disable canvas in Webpack. - Updated package.json to include new dependencies for OnlyOffice and PDF.js. - Added global styles for OnlyOffice theme integration in the CSS. - Created new layout and page components for the Drive feature, including public sharing and editing functionalities. - Updated metadata handling across various layouts to reflect the new app structure.
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
"use client"
|
|
|
|
import { useMemo } from "react"
|
|
import type { DriveFileInfo } from "@/lib/api/types"
|
|
import { useDriveFilterCorpus } from "@/lib/api/hooks/use-drive-queries"
|
|
import {
|
|
applyDriveFilters,
|
|
buildDriveFolderPathsWithMatches,
|
|
} from "@/lib/drive/drive-filters"
|
|
import { sortDriveItems } from "@/lib/drive/drive-sort"
|
|
import type { DriveFolderPlacement, DriveSortField } from "@/lib/stores/drive-settings-store"
|
|
import {
|
|
driveFiltersActive,
|
|
type DriveFiltersSnapshot,
|
|
} from "@/lib/stores/drive-filters-store"
|
|
|
|
export function useDriveFilteredItems(
|
|
items: DriveFileInfo[],
|
|
filters: DriveFiltersSnapshot,
|
|
sort: {
|
|
sortField: DriveSortField
|
|
sortDir: "asc" | "desc"
|
|
folderPlacement: DriveFolderPlacement
|
|
},
|
|
options?: {
|
|
/** When true, fetch recursive file index under scopePath for folder pruning. */
|
|
recursiveCorpus?: boolean
|
|
scopePath?: string
|
|
}
|
|
) {
|
|
const scopePath = options?.scopePath ?? "/"
|
|
const filtersActive = driveFiltersActive(filters)
|
|
const needsRecursiveCorpus = Boolean(options?.recursiveCorpus && filtersActive)
|
|
const corpusQuery = useDriveFilterCorpus(scopePath, needsRecursiveCorpus)
|
|
|
|
const filteredItems = useMemo(() => {
|
|
if (!filtersActive) {
|
|
return sortDriveItems(items, sort)
|
|
}
|
|
|
|
const filterOptions = needsRecursiveCorpus
|
|
? corpusQuery.data?.files
|
|
? {
|
|
folderKeepPaths: buildDriveFolderPathsWithMatches(
|
|
corpusQuery.data.files,
|
|
filters,
|
|
scopePath
|
|
),
|
|
}
|
|
: corpusQuery.isError
|
|
? { matchCorpus: items, scopePath }
|
|
: undefined
|
|
: { matchCorpus: items, scopePath }
|
|
|
|
const filtered = applyDriveFilters(items, filters, filterOptions)
|
|
return sortDriveItems(filtered, sort)
|
|
}, [
|
|
items,
|
|
filters,
|
|
sort,
|
|
filtersActive,
|
|
needsRecursiveCorpus,
|
|
corpusQuery.data?.files,
|
|
corpusQuery.isError,
|
|
scopePath,
|
|
])
|
|
|
|
const corpusLoading = needsRecursiveCorpus && corpusQuery.isLoading && !corpusQuery.data
|
|
|
|
return { filteredItems, corpusLoading, filtersActive }
|
|
}
|