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

fix(files): make filesystem progress/total size reactive #3754

Merged
merged 1 commit into from
Jun 20, 2022
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
2 changes: 1 addition & 1 deletion components/views/files/aside/Aside.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
v-tooltip.bottom="$t('pages.files.aside.coming_soon')"
/>
</div>
<UiProgress :progress="progress" />
<UiProgress :progress="fileSystem.percentageUsed" />
<div class="usage-text">
<span :class="sizeColor">{{totalSize}}</span>
<span>of {{sizeLimit}}</span>
Expand Down
19 changes: 7 additions & 12 deletions components/views/files/aside/Aside.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<template src="./Aside.html"></template>
<script lang="ts">
import Vue from 'vue'
import { mapState } from 'vuex'
import { SimpleItem } from '~/types/ui/sidebar'
import { FileAsideRouteEnum, FileIconsEnum } from '~/libraries/Enums/enums'
import { RootState } from '~/types/store/store'

export default Vue.extend({
data() {
return {
progress: this.$FileSystem.percentStorageUsed as number,
}
},
computed: {
...mapState({
fileSystem: (state) => (state as RootState).textile.fileSystem,
}),
/**
* @description total size of all uploaded files
*/
totalSize(): string {
return this.$filesize(this.$FileSystem.totalSize)
return this.$filesize(this.fileSystem.totalSize)
},
/**
* @description storage space (free tier is 4GB)
Expand All @@ -24,7 +24,7 @@ export default Vue.extend({
return this.$filesize(this.$Config.personalFilesLimit)
},
sizeColor(): string {
return this.progress > 90 ? 'red' : 'green'
return this.fileSystem.percentageUsed > 90 ? 'red' : 'green'
},
quickAccessOptions(): SimpleItem[] {
return [
Expand Down Expand Up @@ -66,11 +66,6 @@ export default Vue.extend({
]
},
},
watch: {
totalSize() {
this.progress = this.$FileSystem.percentStorageUsed
},
},
})
</script>
<style scoped lang="less" src="./Aside.less"></style>
4 changes: 4 additions & 0 deletions store/textile/__snapshots__/state.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Object {
"activeConversation": "",
"conversationLoading": false,
"conversations": Object {},
"fileSystem": Object {
"percentageUsed": 0,
"totalSize": 0,
},
"initialized": false,
"messageLoading": false,
"uploadProgress": Object {},
Expand Down
11 changes: 10 additions & 1 deletion store/textile/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ export default {
config: TextileConfig,
) {
const $TextileManager: TextileManager = Vue.prototype.$TextileManager
const $FileSystem: FilSystem = Vue.prototype.$FileSystem

await $TextileManager.init(config)
commit('setFileSystem', {
totalSize: $FileSystem.totalSize,
percentageUsed: $FileSystem.percentStorageUsed,
})

const textilePublicKey = $TextileManager.getIdentityPublicKey()

Expand Down Expand Up @@ -1142,7 +1147,7 @@ export default {
/**
* @description export filesystem index to textile bucket and update threaddb version
*/
async exportFileSystem({ dispatch }: ActionsArguments<TextileState>) {
async exportFileSystem({ dispatch, commit }: ActionsArguments<TextileState>) {
const $TextileManager: TextileManager = Vue.prototype.$TextileManager
const $FileSystem: FilSystem = Vue.prototype.$FileSystem

Expand All @@ -1154,6 +1159,10 @@ export default {
dispatch('updateUserThreadData', {
filesVersion: $FileSystem.version,
})
commit('setFileSystem', {
totalSize: $FileSystem.totalSize,
percentageUsed: $FileSystem.percentStorageUsed,
})
},

/**
Expand Down
3 changes: 3 additions & 0 deletions store/textile/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ const mutations = {
setUserThreadData(state: TextileState, data: UserThreadData) {
state.userThread = data
},
setFileSystem(state: TextileState, data: TextileState['fileSystem']) {
state.fileSystem = data
},
}

export default mutations
4 changes: 4 additions & 0 deletions store/textile/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const InitialTextileState = (): TextileState => ({
blockNsfw: true,
flipVideo: true,
},
fileSystem: {
totalSize: 0,
percentageUsed: 0,
},
})

export default InitialTextileState
4 changes: 4 additions & 0 deletions store/textile/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export interface TextileState {
}
}
userThread: UserThreadData
fileSystem: {
totalSize: number
percentageUsed: number
}
}

export enum TextileError {
Expand Down