1 import type { UseCaseInterface } from '../Domain/UseCase/UseCaseInterface'
2 import { Result } from '@proton/docs-shared'
3 import type { DriveCompat, DocumentNodeMeta, NodeMeta, DecryptedNode } from '@proton/drive-store'
4 import type { GetDocumentMeta } from './GetDocumentMeta'
5 import { getErrorString } from '../Util/GetErrorString'
8 * Creates a new document from within the Docs client. This is used when selecting "New Document" from the UI.
10 export class CreateNewDocument implements UseCaseInterface<DocumentNodeMeta> {
12 private driveCompat: DriveCompat,
13 private getDocumentMeta: GetDocumentMeta,
18 siblingMeta: NodeMeta,
19 siblingNode: DecryptedNode,
20 ): Promise<Result<DocumentNodeMeta>> {
22 const parentMeta: NodeMeta = siblingNode.parentNodeId
24 volumeId: siblingMeta.volumeId,
25 linkId: siblingNode.parentNodeId,
27 : await this.driveCompat.getMyFilesNodeMeta()
29 const name = await this.driveCompat.findAvailableNodeName(parentMeta, desiredName)
30 const shellResult = await this.driveCompat.createDocumentNode(parentMeta, name)
32 const createResult = await this.getDocumentMeta.execute({
33 volumeId: shellResult.volumeId,
34 linkId: shellResult.linkId,
37 if (createResult.isFailed()) {
38 return Result.fail(createResult.getError())
41 return Result.ok(shellResult)
43 return Result.fail(getErrorString(error) ?? 'Failed to create new document')