mirror of
https://github.com/get-drexa/drive.git
synced 2025-11-30 21:41:39 +00:00
feat: add trash page
This commit is contained in:
2
packages/convex/_generated/api.d.ts
vendored
2
packages/convex/_generated/api.d.ts
vendored
@@ -13,7 +13,6 @@ import type {
|
||||
FilterApi,
|
||||
FunctionReference,
|
||||
} from "convex/server";
|
||||
import type * as admin from "../admin.js";
|
||||
import type * as files from "../files.js";
|
||||
import type * as filesystem from "../filesystem.js";
|
||||
import type * as functions from "../functions.js";
|
||||
@@ -33,7 +32,6 @@ import type * as users from "../users.js";
|
||||
* ```
|
||||
*/
|
||||
declare const fullApi: ApiFromModules<{
|
||||
admin: typeof admin;
|
||||
files: typeof files;
|
||||
filesystem: typeof filesystem;
|
||||
functions: typeof functions;
|
||||
|
||||
@@ -50,15 +50,6 @@ export const fetchDirectory = authenticatedQuery({
|
||||
},
|
||||
})
|
||||
|
||||
export const fetchDirectoryContent = authenticatedQuery({
|
||||
args: {
|
||||
directoryId: v.optional(v.id("directories")),
|
||||
},
|
||||
handler: async (ctx, { directoryId }): Promise<FileSystemItem[]> => {
|
||||
return await Directories.fetchContent(ctx, { directoryId })
|
||||
},
|
||||
})
|
||||
|
||||
export const createDirectory = authenticatedMutation({
|
||||
args: {
|
||||
name: v.string(),
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { v } from "convex/values"
|
||||
import { authenticatedMutation } from "./functions"
|
||||
import { authenticatedMutation, authenticatedQuery } from "./functions"
|
||||
import * as Directories from "./model/directories"
|
||||
import * as Err from "./model/error"
|
||||
import * as Files from "./model/files"
|
||||
import type { DirectoryHandle, FileHandle } from "./model/filesystem"
|
||||
import type {
|
||||
DirectoryHandle,
|
||||
FileHandle,
|
||||
FileSystemItem,
|
||||
} from "./model/filesystem"
|
||||
import {
|
||||
type FileSystemHandle,
|
||||
FileType,
|
||||
VDirectoryHandle,
|
||||
VFileSystemHandle,
|
||||
} from "./model/filesystem"
|
||||
|
||||
export const moveItems = authenticatedMutation({
|
||||
args: {
|
||||
targetDirectory: VDirectoryHandle,
|
||||
@@ -100,3 +103,16 @@ export const moveToTrash = authenticatedMutation({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const fetchDirectoryContent = authenticatedQuery({
|
||||
args: {
|
||||
directoryId: v.optional(v.id("directories")),
|
||||
trashed: v.boolean(),
|
||||
},
|
||||
handler: async (
|
||||
ctx,
|
||||
{ directoryId, trashed },
|
||||
): Promise<FileSystemItem[]> => {
|
||||
return await Directories.fetchContent(ctx, { directoryId, trashed })
|
||||
},
|
||||
})
|
||||
|
||||
@@ -75,7 +75,10 @@ export async function fetch(
|
||||
|
||||
export async function fetchContent(
|
||||
ctx: AuthenticatedQueryCtx,
|
||||
{ directoryId }: { directoryId?: Id<"directories"> } = {},
|
||||
{
|
||||
directoryId,
|
||||
trashed,
|
||||
}: { directoryId?: Id<"directories">; trashed: boolean },
|
||||
): Promise<FileSystemItem[]> {
|
||||
let dirId: Id<"directories"> | undefined
|
||||
if (directoryId) {
|
||||
@@ -85,21 +88,33 @@ export async function fetchContent(
|
||||
const [files, directories] = await Promise.all([
|
||||
ctx.db
|
||||
.query("files")
|
||||
.withIndex("byDirectoryId", (q) =>
|
||||
q
|
||||
.withIndex("byDirectoryId", (q) => {
|
||||
if (trashed) {
|
||||
return q
|
||||
.eq("userId", ctx.user._id)
|
||||
.eq("directoryId", dirId)
|
||||
.gte("deletedAt", 0)
|
||||
}
|
||||
return q
|
||||
.eq("userId", ctx.user._id)
|
||||
.eq("directoryId", dirId)
|
||||
.eq("deletedAt", undefined),
|
||||
)
|
||||
.eq("deletedAt", undefined)
|
||||
})
|
||||
.collect(),
|
||||
ctx.db
|
||||
.query("directories")
|
||||
.withIndex("byParentId", (q) =>
|
||||
q
|
||||
.withIndex("byParentId", (q) => {
|
||||
if (trashed) {
|
||||
return q
|
||||
.eq("userId", ctx.user._id)
|
||||
.eq("parentId", dirId)
|
||||
.gte("deletedAt", 0)
|
||||
}
|
||||
return q
|
||||
.eq("userId", ctx.user._id)
|
||||
.eq("parentId", dirId)
|
||||
.eq("deletedAt", undefined),
|
||||
)
|
||||
.eq("deletedAt", undefined)
|
||||
})
|
||||
.collect(),
|
||||
])
|
||||
|
||||
@@ -216,7 +231,10 @@ export async function move(
|
||||
ignoredHandles.add(handle)
|
||||
} else {
|
||||
promises.push(
|
||||
ctx.db.patch(handle.id, { parentId: targetDirectory.id, updatedAt: Date.now() }),
|
||||
ctx.db.patch(handle.id, {
|
||||
parentId: targetDirectory.id,
|
||||
updatedAt: Date.now(),
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user