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

feat: check for files beta role #986

Merged
merged 10 commits into from
Apr 19, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import { FunctionComponent } from 'preact'
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
import { Icon } from '@/Components/Icon'
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
import {
ChallengeReason,
ContentType,
FeatureIdentifier,
FeatureStatus,
SNFile,
} from '@standardnotes/snjs'
import { ChallengeReason, ContentType, SNFile } from '@standardnotes/snjs'
import { confirmDialog } from '@/Services/AlertService'
import { addToast, dismissToast, ToastType } from '@standardnotes/stylekit'
import { StreamingFileReader } from '@standardnotes/filepicker'
Expand Down Expand Up @@ -78,9 +72,7 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
}, [application, reloadAttachedFilesCount])

const toggleAttachedFilesMenu = useCallback(async () => {
if (
application.features.getFeatureStatus(FeatureIdentifier.Files) !== FeatureStatus.Entitled
) {
if (!appState.features.isEntitledToFiles) {
premiumModal.activate('Files')
return
}
Expand All @@ -107,7 +99,7 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(

setOpen(newOpenState)
}
}, [application.features, onClickPreprocessing, open, premiumModal])
}, [appState.features.isEntitledToFiles, onClickPreprocessing, open, premiumModal])

const deleteFile = async (file: SNFile) => {
const shouldDelete = await confirmDialog({
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/Components/NoteView/NoteView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ export class NoteView extends PureComponent<Props, State> {
)}
</div>
</div>
{window.enabledUnfinishedFeatures && (
{this.appState.features.isFilesEnabled && (
<div className="mr-3">
<AttachedFilesButton
application={this.application}
Expand Down
21 changes: 21 additions & 0 deletions app/assets/javascripts/UIModels/AppState/FeaturesState.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isDev } from '@/Utils'
import { ApplicationEvent, FeatureIdentifier, FeatureStatus } from '@standardnotes/snjs'
import { action, computed, makeObservable, observable, runInAction, when } from 'mobx'
import { WebApplication } from '../Application'
Expand All @@ -16,13 +17,15 @@ export class FeaturesState {

_hasFolders = false
_hasSmartViews = false
_hasFilesBeta = false
_premiumAlertFeatureName: string | undefined

private unsub: () => void

constructor(private application: WebApplication) {
this._hasFolders = this.hasNativeFolders()
this._hasSmartViews = this.hasNativeSmartViews()
this._hasFilesBeta = this.isEntitledToFilesBeta()
this._premiumAlertFeatureName = undefined

makeObservable(this, {
Expand All @@ -44,6 +47,7 @@ export class FeaturesState {
runInAction(() => {
this._hasFolders = this.hasNativeFolders()
this._hasSmartViews = this.hasNativeSmartViews()
this._hasFilesBeta = this.isEntitledToFilesBeta()
})
break
default:
Expand All @@ -64,6 +68,14 @@ export class FeaturesState {
return this._hasSmartViews
}

public get isFilesEnabled(): boolean {
return this._hasFilesBeta || window.enabledUnfinishedFeatures || isDev
}

public get isEntitledToFiles(): boolean {
return this._hasFilesBeta
}

public async showPremiumAlert(featureName: string): Promise<void> {
this._premiumAlertFeatureName = featureName
return when(() => this._premiumAlertFeatureName === undefined)
Expand All @@ -84,4 +96,13 @@ export class FeaturesState {

return status === FeatureStatus.Entitled
}

private isEntitledToFilesBeta(): boolean {
if (window.enabledUnfinishedFeatures) {
return true
}

const status = this.application.features.getFeatureStatus(FeatureIdentifier.FilesBeta)
return status === FeatureStatus.Entitled
}
}