Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] Get rid of getCurrentInstance #9232

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
useSpaceActionsRestore
} from 'web-pkg/src/composables/actions/spaces'
import QuotaModal from 'web-pkg/src/components/Spaces/QuotaModal.vue'
import { computed, defineComponent, getCurrentInstance, inject, unref } from 'vue'
import { computed, defineComponent, inject, unref } from 'vue'
import { SpaceResource } from 'web-client'
import { useCapabilitySpacesMaxQuota, useStore } from 'web-pkg/src/composables'

Expand All @@ -38,7 +38,6 @@ export default defineComponent({
components: { ActionMenuItem, QuotaModal },
setup() {
const store = useStore()
const instance = getCurrentInstance().proxy as any
const resource = inject<SpaceResource>('resource')
const resources = computed(() => {
return [unref(resource)]
Expand Down
96 changes: 43 additions & 53 deletions packages/web-app-files/src/components/AppBar/CreateAndUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
</template>

<script lang="ts">
import { mapActions, mapGetters, mapMutations } from 'vuex'
import { mapActions, mapGetters } from 'vuex'

import { useFileActions } from '../../composables/actions/files/useFileActions'
import { isLocationPublicActive, isLocationSpacesActive } from '../../router'
Expand All @@ -167,16 +167,7 @@ import {
} from 'web-pkg/src/composables'

import ResourceUpload from './Upload/ResourceUpload.vue'
import {
computed,
defineComponent,
getCurrentInstance,
onMounted,
onBeforeUnmount,
PropType,
unref,
watch
} from 'vue'
import { computed, defineComponent, onMounted, onBeforeUnmount, PropType, unref, watch } from 'vue'
import { useUpload } from 'web-runtime/src/composables/upload'
import { eventBus } from 'web-pkg/src/services/eventBus'
import { Resource, SpaceResource, isShareSpaceResource } from 'web-client/src/helpers'
Expand Down Expand Up @@ -212,7 +203,6 @@ export default defineComponent({
}
},
setup(props) {
const instance = getCurrentInstance().proxy as any
const uppyService = useService<UppyService>('$uppyService')
const clientService = useClientService()
const store = useStore()
Expand Down Expand Up @@ -291,8 +281,44 @@ export default defineComponent({
event.preventDefault()
}

const onUploadComplete = async (result) => {
if (result.successful) {
const file = result.successful[0]

if (!file) {
return
}

store.dispatch('hideModal')
const { spaceId, currentFolder, currentFolderId } = file.meta
if (!['public', 'share'].includes(file.meta.driveType)) {
if (unref(hasSpaces)) {
const client = clientService.graphAuthenticated
const driveResponse = await client.drives.getDrive(spaceId)
store.commit('runtime/spaces/UPDATE_SPACE_FIELD', {
id: driveResponse.data.id,
field: 'spaceQuota',
value: driveResponse.data.quota
})
} else {
const user = await clientService.owncloudSdk.users.getUser(store.getters.user.id)
store.commit('SET_QUOTA', user.quota)
}
}

const sameFolder =
props.itemId && !isShareSpaceResource(props.space)
? props.itemId.toString().startsWith(currentFolderId)
: currentFolder === props.item
const fileIsInCurrentPath = spaceId === props.space.id && sameFolder
if (fileIsInCurrentPath) {
eventBus.publish('app.files.list.load')
}
}
}

onMounted(() => {
uploadCompletedSub = uppyService.subscribe('uploadCompleted', instance.onUploadComplete)
uploadCompletedSub = uppyService.subscribe('uploadCompleted', onUploadComplete)
document.addEventListener('paste', handlePasteFileEvent)
})

Expand Down Expand Up @@ -331,7 +357,10 @@ export default defineComponent({
createNewFolder,
mimetypesAllowedForCreation,
createNewFolderAction,
extensionActions
extensionActions,

// HACK: exported for unit tests:
onUploadComplete
}
},
computed: {
Expand Down Expand Up @@ -398,9 +427,6 @@ export default defineComponent({
methods: {
...mapActions('Files', ['clearClipboardFiles', 'pasteSelectedFiles']),
...mapActions(['showMessage', 'createModal', 'hideModal']),
...mapMutations('Files', ['UPSERT_RESOURCE']),
...mapMutations('runtime/spaces', ['UPDATE_SPACE_FIELD']),
...mapMutations(['SET_QUOTA']),

pasteFilesHere() {
this.pasteSelectedFiles({
Expand All @@ -418,42 +444,6 @@ export default defineComponent({
})
},

async onUploadComplete(result) {
if (result.successful) {
const file = result.successful[0]

if (!file) {
return
}

this.hideModal()
const { spaceId, currentFolder, currentFolderId } = file.meta
if (!['public', 'share'].includes(file.meta.driveType)) {
if (this.hasSpaces) {
const client = this.clientService.graphAuthenticated
const driveResponse = await client.drives.getDrive(spaceId)
this.UPDATE_SPACE_FIELD({
id: driveResponse.data.id,
field: 'spaceQuota',
value: driveResponse.data.quota
})
} else {
const user = await this.$client.users.getUser(this.user.id)
this.SET_QUOTA(user.quota)
}
}

const sameFolder =
this.itemId && !isShareSpaceResource(this.space)
? this.itemId.toString().startsWith(currentFolderId)
: currentFolder === this.item
const fileIsInCurrentPath = spaceId === this.space.id && sameFolder
if (fileIsInCurrentPath) {
eventBus.publish('app.files.list.load')
}
}
},

getIconResource(fileHandler) {
return { type: 'file', extension: fileHandler.ext } as Resource
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ import {
locationSharesWithMe,
locationSharesWithOthers
} from '../../router/shares'
import { computed, defineComponent, getCurrentInstance, unref } from 'vue'
import { computed, defineComponent, unref } from 'vue'
import { useRouter } from 'web-pkg/src/composables'
import { useActiveLocation } from '../../composables'
import { useGettext } from 'vue3-gettext'

export default defineComponent({
setup() {
const $gettext = getCurrentInstance().proxy.$gettext
const { $gettext } = useGettext()
const router = useRouter()
const sharesRoutes = [
locationSharesWithMe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@

<script lang="ts">
import { DateTime } from 'luxon'
import { computed, getCurrentInstance, watch, defineComponent, customRef } from 'vue'
import { computed, watch, defineComponent, customRef } from 'vue'
import { useStore } from 'web-pkg/src/composables'
import { ShareTypes } from 'web-client/src/helpers/share'
import { formatRelativeDateFromDateTime, getLocaleFromLanguage } from 'web-pkg/src/helpers'
import { useGettext } from 'vue3-gettext'

export default defineComponent({
name: 'DateCurrentpicker',
Expand All @@ -66,15 +67,14 @@ export default defineComponent({
},
emits: ['optionChange'],
setup(props, { emit }) {
const vm = getCurrentInstance().proxy
const language = computed(() => vm.$language)
const language = useGettext()
const store = useStore()
const capabilities = computed(() => store.getters.capabilities)
const optionsUser = computed(() => capabilities.value.files_sharing.user?.expire_date)
const optionsGroup = computed(() => capabilities.value.files_sharing.group?.expire_date)
const available = computed(() => optionsUser.value || optionsGroup.value)
const enforced = computed(() => optionsUser.value?.enforced || optionsGroup.value?.enforced)
const dateMin = DateTime.now().setLocale(language.value.current).toJSDate()
const dateMin = DateTime.now().setLocale(language.current).toJSDate()
const dateDefault = computed(() => {
const hasUserCollaborators = props.shareTypes.includes(ShareTypes.user.value)
const hasGroupCollaborators = props.shareTypes.includes(ShareTypes.group.value)
Expand Down Expand Up @@ -104,7 +104,7 @@ export default defineComponent({
}

return DateTime.now()
.setLocale(getLocaleFromLanguage(language.value.current))
.setLocale(getLocaleFromLanguage(language.current))
.plus({ days })
.toJSDate()
})
Expand All @@ -125,13 +125,13 @@ export default defineComponent({
const dateExpire = computed(() =>
formatRelativeDateFromDateTime(
DateTime.fromJSDate(dateCurrent.value).endOf('day'),
language.value.current
language.current
)
)

watch(dateCurrent, (val) => {
const dateCurrent = DateTime.fromJSDate(val)
.setLocale(getLocaleFromLanguage(language.value.current))
.setLocale(getLocaleFromLanguage(language.current))
.endOf('day')
emit('optionChange', {
expirationDate: dateCurrent.isValid
Expand Down