feat: check for files beta role (#986)
This commit is contained in:
@@ -8,13 +8,7 @@ import { FunctionComponent } from 'preact'
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
|
||||||
import { Icon } from '@/Components/Icon'
|
import { Icon } from '@/Components/Icon'
|
||||||
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
|
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
|
||||||
import {
|
import { ChallengeReason, ContentType, SNFile } from '@standardnotes/snjs'
|
||||||
ChallengeReason,
|
|
||||||
ContentType,
|
|
||||||
FeatureIdentifier,
|
|
||||||
FeatureStatus,
|
|
||||||
SNFile,
|
|
||||||
} from '@standardnotes/snjs'
|
|
||||||
import { confirmDialog } from '@/Services/AlertService'
|
import { confirmDialog } from '@/Services/AlertService'
|
||||||
import { addToast, dismissToast, ToastType } from '@standardnotes/stylekit'
|
import { addToast, dismissToast, ToastType } from '@standardnotes/stylekit'
|
||||||
import { StreamingFileReader } from '@standardnotes/filepicker'
|
import { StreamingFileReader } from '@standardnotes/filepicker'
|
||||||
@@ -78,9 +72,7 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
|
|||||||
}, [application, reloadAttachedFilesCount])
|
}, [application, reloadAttachedFilesCount])
|
||||||
|
|
||||||
const toggleAttachedFilesMenu = useCallback(async () => {
|
const toggleAttachedFilesMenu = useCallback(async () => {
|
||||||
if (
|
if (!appState.features.isEntitledToFiles) {
|
||||||
application.features.getFeatureStatus(FeatureIdentifier.Files) !== FeatureStatus.Entitled
|
|
||||||
) {
|
|
||||||
premiumModal.activate('Files')
|
premiumModal.activate('Files')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -107,7 +99,7 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
|
|||||||
|
|
||||||
setOpen(newOpenState)
|
setOpen(newOpenState)
|
||||||
}
|
}
|
||||||
}, [application.features, onClickPreprocessing, open, premiumModal])
|
}, [appState.features.isEntitledToFiles, onClickPreprocessing, open, premiumModal])
|
||||||
|
|
||||||
const deleteFile = async (file: SNFile) => {
|
const deleteFile = async (file: SNFile) => {
|
||||||
const shouldDelete = await confirmDialog({
|
const shouldDelete = await confirmDialog({
|
||||||
|
|||||||
@@ -989,7 +989,7 @@ export class NoteView extends PureComponent<Props, State> {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{window.enabledUnfinishedFeatures && (
|
{this.appState.features.isFilesEnabled && (
|
||||||
<div className="mr-3">
|
<div className="mr-3">
|
||||||
<AttachedFilesButton
|
<AttachedFilesButton
|
||||||
application={this.application}
|
application={this.application}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { isDev } from '@/Utils'
|
||||||
import { ApplicationEvent, FeatureIdentifier, FeatureStatus } from '@standardnotes/snjs'
|
import { ApplicationEvent, FeatureIdentifier, FeatureStatus } from '@standardnotes/snjs'
|
||||||
import { action, computed, makeObservable, observable, runInAction, when } from 'mobx'
|
import { action, computed, makeObservable, observable, runInAction, when } from 'mobx'
|
||||||
import { WebApplication } from '../Application'
|
import { WebApplication } from '../Application'
|
||||||
@@ -16,6 +17,7 @@ export class FeaturesState {
|
|||||||
|
|
||||||
_hasFolders = false
|
_hasFolders = false
|
||||||
_hasSmartViews = false
|
_hasSmartViews = false
|
||||||
|
_hasFilesBeta = false
|
||||||
_premiumAlertFeatureName: string | undefined
|
_premiumAlertFeatureName: string | undefined
|
||||||
|
|
||||||
private unsub: () => void
|
private unsub: () => void
|
||||||
@@ -23,6 +25,7 @@ export class FeaturesState {
|
|||||||
constructor(private application: WebApplication) {
|
constructor(private application: WebApplication) {
|
||||||
this._hasFolders = this.hasNativeFolders()
|
this._hasFolders = this.hasNativeFolders()
|
||||||
this._hasSmartViews = this.hasNativeSmartViews()
|
this._hasSmartViews = this.hasNativeSmartViews()
|
||||||
|
this._hasFilesBeta = this.isEntitledToFilesBeta()
|
||||||
this._premiumAlertFeatureName = undefined
|
this._premiumAlertFeatureName = undefined
|
||||||
|
|
||||||
makeObservable(this, {
|
makeObservable(this, {
|
||||||
@@ -44,6 +47,7 @@ export class FeaturesState {
|
|||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this._hasFolders = this.hasNativeFolders()
|
this._hasFolders = this.hasNativeFolders()
|
||||||
this._hasSmartViews = this.hasNativeSmartViews()
|
this._hasSmartViews = this.hasNativeSmartViews()
|
||||||
|
this._hasFilesBeta = this.isEntitledToFilesBeta()
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@@ -64,6 +68,14 @@ export class FeaturesState {
|
|||||||
return this._hasSmartViews
|
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> {
|
public async showPremiumAlert(featureName: string): Promise<void> {
|
||||||
this._premiumAlertFeatureName = featureName
|
this._premiumAlertFeatureName = featureName
|
||||||
return when(() => this._premiumAlertFeatureName === undefined)
|
return when(() => this._premiumAlertFeatureName === undefined)
|
||||||
@@ -84,4 +96,13 @@ export class FeaturesState {
|
|||||||
|
|
||||||
return status === FeatureStatus.Entitled
|
return status === FeatureStatus.Entitled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isEntitledToFilesBeta(): boolean {
|
||||||
|
if (window.enabledUnfinishedFeatures) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = this.application.features.getFeatureStatus(FeatureIdentifier.FilesBeta)
|
||||||
|
return status === FeatureStatus.Entitled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user