Skip to content

Commit

Permalink
Feat: Add warning popup to editors, when file exceeds threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndBear committed Oct 7, 2024
1 parent 33699ba commit da5927e
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions packages/web-pkg/src/components/AppTemplates/AppWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ import { HttpError } from '@ownclouders/web-client'
import { dirname } from 'path'
import { useFileActionsOpenWithApp } from '../../composables/actions/files/useFileActionsOpenWithApp'
import { UnsavedChangesModal } from '../Modals'
import { formatFileSize } from '../../helpers'
import toNumber from 'lodash-es/toNumber'
const FILE_SIZE_WARNING_THRESHOLD = 4000000
export default defineComponent({
name: 'AppWrapper',
Expand Down Expand Up @@ -126,7 +130,7 @@ export default defineComponent({
}
},
setup(props) {
const { $gettext } = useGettext()
const { $gettext, current: currentLanguage } = useGettext()
const appsStore = useAppsStore()
const { showMessage, showErrorMessage } = useMessages()
const router = useRouter()
Expand Down Expand Up @@ -264,17 +268,24 @@ export default defineComponent({
})
}
const loadFileTask = useTask(function* (signal) {
const loadResourceTask = useTask(function* (signal) {
try {
if (!unref(driveAliasAndItem)) {
yield addMissingDriveAliasAndItem()
}
space.value = unref(unref(currentFileContext).space)
resource.value = yield getFileInfo(currentFileContext)
resource.value = yield getFileInfo(currentFileContext, { signal })
resourcesStore.initResourceList({ currentFolder: null, resources: [unref(resource)] })
selectedResources.value = [unref(resource)]
} catch (e) {
console.error(e)
loadingError.value = e
loading.value = false
}
}).restartable()
const loadFileTask = useTask(function* (signal) {
try {
const newExtension = props.importResourceWithExtension(unref(resource))
if (newExtension) {
const timestamp = DateTime.local().toFormat('yyyyMMddHHmmss')
Expand Down Expand Up @@ -328,9 +339,33 @@ export default defineComponent({
watch(
currentFileContext,
() => {
async () => {
if (!unref(noResourceLoading)) {
loadFileTask.perform()
await loadResourceTask.perform()
if (unref(isEditor) && toNumber(unref(resource).size) > FILE_SIZE_WARNING_THRESHOLD) {
dispatchModal({
title: $gettext('File %{resource} exceeds %{threshold}', {
resource: unref(resource).name,
threshold: formatFileSize(FILE_SIZE_WARNING_THRESHOLD, currentLanguage)
}),
message: $gettext(
'This file exceeds the recommended size %{threshold} for editing, and may cause performance issues.',
{
threshold: formatFileSize(FILE_SIZE_WARNING_THRESHOLD, currentLanguage)
}
),
confirmText: $gettext('Continue'),
onCancel: () => {
closeApp()
},
onConfirm: () => {
loadFileTask.perform()
}
})
} else {
loadFileTask.perform()
}
}
},
{ immediate: true }
Expand Down

0 comments on commit da5927e

Please sign in to comment.