feat: display files quota in preferences (#994)
This commit is contained in:
@@ -110,7 +110,7 @@ export class AppState {
|
||||
this.subscription = new SubscriptionState(application, this.appEventObserverRemovers)
|
||||
this.purchaseFlow = new PurchaseFlowState(application)
|
||||
this.notesView = new NotesViewState(application, this, this.appEventObserverRemovers)
|
||||
this.files = new FilesState(application)
|
||||
this.files = new FilesState(application, this.appEventObserverRemovers)
|
||||
this.addAppEventObserver()
|
||||
this.streamNotesAndTags()
|
||||
this.onVisibilityChange = () => {
|
||||
|
||||
@@ -7,13 +7,61 @@ import {
|
||||
ClassicFileSaver,
|
||||
parseFileName,
|
||||
} from '@standardnotes/filepicker'
|
||||
import { ClientDisplayableError, SNFile } from '@standardnotes/snjs'
|
||||
import {
|
||||
ApplicationEvent,
|
||||
ClientDisplayableError,
|
||||
ContentType,
|
||||
SNFile,
|
||||
SubscriptionSettingName,
|
||||
} from '@standardnotes/snjs'
|
||||
import { addToast, dismissToast, ToastType } from '@standardnotes/stylekit'
|
||||
import { action, makeObservable, observable } from 'mobx'
|
||||
|
||||
import { WebApplication } from '../Application'
|
||||
|
||||
export class FilesState {
|
||||
constructor(private application: WebApplication) {}
|
||||
filesQuotaUsed: number
|
||||
filesQuotaTotal: number
|
||||
|
||||
constructor(private application: WebApplication, appObservers: (() => void)[]) {
|
||||
this.filesQuotaUsed = 0
|
||||
this.filesQuotaTotal = 0
|
||||
|
||||
makeObservable(this, {
|
||||
filesQuotaUsed: observable,
|
||||
filesQuotaTotal: observable,
|
||||
getFilesQuota: action,
|
||||
})
|
||||
|
||||
appObservers.push(
|
||||
application.addEventObserver(async (event) => {
|
||||
switch (event) {
|
||||
case ApplicationEvent.Launched:
|
||||
case ApplicationEvent.SignedIn:
|
||||
this.getFilesQuota().catch(console.error)
|
||||
}
|
||||
}),
|
||||
application.streamItems(ContentType.File, () => {
|
||||
this.getFilesQuota().catch(console.error)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
public async getFilesQuota() {
|
||||
const filesQuotaUsed = await this.application.settings.getSubscriptionSetting(
|
||||
SubscriptionSettingName.FileUploadBytesUsed,
|
||||
)
|
||||
const filesQuotaTotal = await this.application.settings.getSubscriptionSetting(
|
||||
SubscriptionSettingName.FileUploadBytesLimit,
|
||||
)
|
||||
|
||||
if (filesQuotaUsed) {
|
||||
this.filesQuotaUsed = parseFloat(filesQuotaUsed)
|
||||
}
|
||||
if (filesQuotaTotal) {
|
||||
this.filesQuotaTotal = parseFloat(filesQuotaTotal)
|
||||
}
|
||||
}
|
||||
|
||||
public async downloadFile(file: SNFile): Promise<void> {
|
||||
let downloadingToastId = ''
|
||||
|
||||
Reference in New Issue
Block a user