import { WebApplication } from '@/UIModels/Application' import { AppState } from '@/UIModels/AppState' import { formatSizeToReadableString } from '@standardnotes/filepicker' import { SubscriptionSettingName } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' import { FunctionComponent } from 'preact' import { useEffect, useState } from 'preact/hooks' import { PreferencesGroup, PreferencesSegment, Subtitle, Title } from '../../PreferencesComponents' type Props = { application: WebApplication appState: AppState } export const FilesSection: FunctionComponent = observer(({ application, appState }) => { if (!application.getUser() || !appState.features.isEntitledToFiles) { return null } const [isLoading, setIsLoading] = useState(true) const [filesQuotaUsed, setFilesQuotaUsed] = useState(0) const [filesQuotaTotal, setFilesQuotaTotal] = useState(0) useEffect(() => { const getFilesQuota = async () => { const filesQuotaUsed = await application.settings.getSubscriptionSetting( SubscriptionSettingName.FileUploadBytesUsed, ) const filesQuotaTotal = await application.settings.getSubscriptionSetting( SubscriptionSettingName.FileUploadBytesLimit, ) if (filesQuotaUsed) { setFilesQuotaUsed(parseFloat(filesQuotaUsed)) } if (filesQuotaTotal) { setFilesQuotaTotal(parseFloat(filesQuotaTotal)) } setIsLoading(false) } getFilesQuota().catch(console.error) }) return ( Files Storage Quota {isLoading ? (
) : ( <>
{formatSizeToReadableString(filesQuotaUsed)} of{' '} {formatSizeToReadableString(filesQuotaTotal)} used
)}
) })