alexusmai / vue-laravel-file-manager

Frontend for Laravel File Manager on Vue.js
MIT License
358 stars 160 forks source link

Set default disk and path on init or any oninit callback ? #117

Open MuratDemirel opened 2 years ago

MuratDemirel commented 2 years ago

I need to set path according view. This code works, but is there any better way?

setImg(input){
    this.$bvModal.show('modal-fm')

    setTimeout(this.setPath, 1000)
    this.$store.commit('fm/setFileCallBack', url => {
        this.formData[input] = url
        this.$bvModal.hide('modal-fm')
    });
},
setPath(){
    this.$store.commit('fm/left/setSelectedDirectory', 'files/faq')
    this.$store.commit('fm/left/addToHistory', 'files/faq')
    this.$store.dispatch('fm/tree/reopenPath', 'files/faq')
    this.$store.dispatch(`fm/left/selectDirectory`, { path:'files/faq', history: true })
}

Vue@2 vue-laravel-file-manager@2.5.3

MuratDemirel commented 2 years ago

Better than before, but defining on settings or having callbacks would great..

data(){
    return{
        foldersLoaded: false
    }
},
watch:{
    '$store.state.fm.tree.directories': function(directories){
        if(!this.foldersLoaded && directories.length){
            this.foldersLoaded = true
            this.setPath()
        }else if(this.foldersLoaded && !directories.length){
            this.foldersLoaded = false
        }
    }
},
methods:{
    setImg(input){
        this.$bvModal.show('modal-fm')

        this.$store.commit('fm/setFileCallBack', url => {
            this.formData[input] = url
            this.$bvModal.hide('modal-fm')
        });
    },
    setPath(){
        this.$store.commit('fm/left/setSelectedDirectory', 'files/faq')
        this.$store.commit('fm/left/addToHistory', 'files/faq')
        this.$store.dispatch('fm/tree/reopenPath', 'files/faq')
        this.$store.dispatch(`fm/left/selectDirectory`, { path:'files/faq', history: true })
    }
}