refactor: use correct endpoint when uploading file to shared vault note
This commit is contained in:
@@ -350,6 +350,7 @@ export class WebDependencies extends DependencyContainer {
|
|||||||
this.get<FilePreviewModalController>(Web_TYPES.FilePreviewModalController),
|
this.get<FilePreviewModalController>(Web_TYPES.FilePreviewModalController),
|
||||||
this.get<ArchiveManager>(Web_TYPES.ArchiveManager),
|
this.get<ArchiveManager>(Web_TYPES.ArchiveManager),
|
||||||
this.get<VaultDisplayService>(Web_TYPES.VaultDisplayService),
|
this.get<VaultDisplayService>(Web_TYPES.VaultDisplayService),
|
||||||
|
application.vaults,
|
||||||
application.items,
|
application.items,
|
||||||
application.files,
|
application.files,
|
||||||
application.mutator,
|
application.mutator,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { usePremiumModal } from '@/Hooks/usePremiumModal'
|
|||||||
import { classNames } from '@standardnotes/utils'
|
import { classNames } from '@standardnotes/utils'
|
||||||
import { isHandlingFileDrag } from '@/Utils/DragTypeCheck'
|
import { isHandlingFileDrag } from '@/Utils/DragTypeCheck'
|
||||||
import { StreamingFileReader } from '@standardnotes/filepicker'
|
import { StreamingFileReader } from '@standardnotes/filepicker'
|
||||||
import { FileItem } from '@standardnotes/snjs'
|
import { FileItem, SNNote } from '@standardnotes/snjs'
|
||||||
import { useMemo, useState, createContext, ReactNode, useRef, useCallback, useEffect, useContext, memo } from 'react'
|
import { useMemo, useState, createContext, ReactNode, useRef, useCallback, useEffect, useContext, memo } from 'react'
|
||||||
import Portal from './Portal/Portal'
|
import Portal from './Portal/Portal'
|
||||||
import { ElementIds } from '@/Constants/ElementIDs'
|
import { ElementIds } from '@/Constants/ElementIDs'
|
||||||
@@ -11,6 +11,7 @@ import { ElementIds } from '@/Constants/ElementIDs'
|
|||||||
type FileDragTargetData = {
|
type FileDragTargetData = {
|
||||||
tooltipText: string
|
tooltipText: string
|
||||||
callback: (files: FileItem) => void
|
callback: (files: FileItem) => void
|
||||||
|
note?: SNNote
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileDnDContextData = {
|
type FileDnDContextData = {
|
||||||
@@ -200,15 +201,17 @@ const FileDragNDropProvider = ({ application, children }: Props) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadedFile = await application.filesController.uploadNewFile(fileOrHandle)
|
const dragTarget = closestDragTarget ? dragTargets.current.get(closestDragTarget) : undefined
|
||||||
|
|
||||||
|
const uploadedFile = await application.filesController.uploadNewFile(fileOrHandle, {
|
||||||
|
note: dragTarget?.note,
|
||||||
|
})
|
||||||
|
|
||||||
if (!uploadedFile) {
|
if (!uploadedFile) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closestDragTarget && dragTargets.current.has(closestDragTarget)) {
|
dragTarget?.callback(uploadedFile)
|
||||||
dragTargets.current.get(closestDragTarget)?.callback(uploadedFile)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
dragCounter.current = 0
|
dragCounter.current = 0
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Icon from '../Icon/Icon'
|
|||||||
import DecoratedInput from '../Input/DecoratedInput'
|
import DecoratedInput from '../Input/DecoratedInput'
|
||||||
import LinkedItemSearchResults from './LinkedItemSearchResults'
|
import LinkedItemSearchResults from './LinkedItemSearchResults'
|
||||||
import { LinkedItemsSectionItem } from './LinkedItemsSectionItem'
|
import { LinkedItemsSectionItem } from './LinkedItemsSectionItem'
|
||||||
import { DecryptedItem } from '@standardnotes/snjs'
|
import { DecryptedItem, SNNote } from '@standardnotes/snjs'
|
||||||
import { useItemLinks } from '@/Hooks/useItemLinks'
|
import { useItemLinks } from '@/Hooks/useItemLinks'
|
||||||
import { mergeRefs } from '@/Hooks/mergeRefs'
|
import { mergeRefs } from '@/Hooks/mergeRefs'
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ const LinkedItemsPanel = ({ item }: { item: DecryptedItem }) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
void application.filesController.selectAndUploadNewFiles((file) => {
|
void application.filesController.selectAndUploadNewFiles(item instanceof SNNote ? item : undefined, (file) => {
|
||||||
void linkItems(item, file)
|
void linkItems(item, file)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const NoteViewFileDropTarget = ({ note, linkingController, noteViewElement, file
|
|||||||
})
|
})
|
||||||
filesController.notifyObserversOfUploadedFileLinkingToCurrentNote(uploadedFile.uuid)
|
filesController.notifyObserversOfUploadedFileLinkingToCurrentNote(uploadedFile.uuid)
|
||||||
},
|
},
|
||||||
|
note,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ import {
|
|||||||
MutatorClientInterface,
|
MutatorClientInterface,
|
||||||
Platform,
|
Platform,
|
||||||
ProtectionsClientInterface,
|
ProtectionsClientInterface,
|
||||||
|
SNNote,
|
||||||
SyncServiceInterface,
|
SyncServiceInterface,
|
||||||
|
VaultServiceInterface,
|
||||||
} from '@standardnotes/snjs'
|
} from '@standardnotes/snjs'
|
||||||
import { addToast, dismissToast, ToastType, updateToast } from '@standardnotes/toast'
|
import { addToast, dismissToast, ToastType, updateToast } from '@standardnotes/toast'
|
||||||
import { action, makeObservable, observable, reaction } from 'mobx'
|
import { action, makeObservable, observable, reaction } from 'mobx'
|
||||||
@@ -80,6 +82,7 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
|
|||||||
private filePreviewModalController: FilePreviewModalController,
|
private filePreviewModalController: FilePreviewModalController,
|
||||||
private archiveService: ArchiveManager,
|
private archiveService: ArchiveManager,
|
||||||
private vaultDisplayService: VaultDisplayServiceInterface,
|
private vaultDisplayService: VaultDisplayServiceInterface,
|
||||||
|
private vaults: VaultServiceInterface,
|
||||||
private items: ItemManagerInterface,
|
private items: ItemManagerInterface,
|
||||||
private files: FilesClientInterface,
|
private files: FilesClientInterface,
|
||||||
private mutator: MutatorClientInterface,
|
private mutator: MutatorClientInterface,
|
||||||
@@ -369,14 +372,16 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
public async selectAndUploadNewFiles(callback?: (file: FileItem) => void) {
|
public async selectAndUploadNewFiles(note?: SNNote, callback?: (file: FileItem) => void) {
|
||||||
const selectedFiles = await this.reader.selectFiles()
|
const selectedFiles = await this.reader.selectFiles()
|
||||||
|
|
||||||
selectedFiles.forEach(async (file) => {
|
selectedFiles.forEach(async (file) => {
|
||||||
if (this.alertIfFileExceedsSizeLimit(file)) {
|
if (this.alertIfFileExceedsSizeLimit(file)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const uploadedFile = await this.uploadNewFile(file)
|
const uploadedFile = await this.uploadNewFile(file, {
|
||||||
|
note,
|
||||||
|
})
|
||||||
if (uploadedFile && callback) {
|
if (uploadedFile && callback) {
|
||||||
callback(uploadedFile)
|
callback(uploadedFile)
|
||||||
}
|
}
|
||||||
@@ -385,7 +390,15 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
|
|||||||
|
|
||||||
public async uploadNewFile(
|
public async uploadNewFile(
|
||||||
fileOrHandle: File | FileSystemFileHandle,
|
fileOrHandle: File | FileSystemFileHandle,
|
||||||
showToast = true,
|
{
|
||||||
|
showToast,
|
||||||
|
note,
|
||||||
|
}: {
|
||||||
|
showToast?: boolean
|
||||||
|
note?: SNNote
|
||||||
|
} = {
|
||||||
|
showToast: true,
|
||||||
|
},
|
||||||
): Promise<FileItem | undefined> {
|
): Promise<FileItem | undefined> {
|
||||||
let toastId: string | undefined
|
let toastId: string | undefined
|
||||||
|
|
||||||
@@ -407,9 +420,11 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const vaultForNote = note ? this.vaults.getItemVault(note) : undefined
|
||||||
|
|
||||||
const operation = await this.files.beginNewFileUpload(
|
const operation = await this.files.beginNewFileUpload(
|
||||||
fileToUpload.size,
|
fileToUpload.size,
|
||||||
this.vaultDisplayService.exclusivelyShownVault,
|
vaultForNote || this.vaultDisplayService.exclusivelyShownVault,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (operation instanceof ClientDisplayableError) {
|
if (operation instanceof ClientDisplayableError) {
|
||||||
|
|||||||
Reference in New Issue
Block a user