From 0561e9ba5d54f8fb4bcec03f7c2f1f9bf9af3cbf Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Tue, 19 Apr 2022 19:35:33 +0530 Subject: [PATCH 1/6] feat: check for files beta role --- .../AttachedFilesPopover/AttachedFilesButton.tsx | 5 ++++- .../javascripts/Components/NoteView/NoteView.tsx | 16 +++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx index af2c3f1cec3..746ae0654e8 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx @@ -21,6 +21,7 @@ import { StreamingFileReader } from '@standardnotes/filepicker' import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' import { AttachedFilesPopover, PopoverTabs } from './AttachedFilesPopover' import { usePremiumModal } from '@/Hooks/usePremiumModal' +import { isDev } from '@/Utils' type Props = { application: WebApplication @@ -79,7 +80,9 @@ export const AttachedFilesButton: FunctionComponent = observer( const toggleAttachedFilesMenu = useCallback(async () => { if ( - application.features.getFeatureStatus(FeatureIdentifier.Files) !== FeatureStatus.Entitled + !isDev && + application.features.getFeatureStatus(FeatureIdentifier.FilesBeta) !== + FeatureStatus.Entitled ) { premiumModal.activate('Files') return diff --git a/app/assets/javascripts/Components/NoteView/NoteView.tsx b/app/assets/javascripts/Components/NoteView/NoteView.tsx index 6ddea293ddf..fa1daa0a345 100644 --- a/app/assets/javascripts/Components/NoteView/NoteView.tsx +++ b/app/assets/javascripts/Components/NoteView/NoteView.tsx @@ -989,15 +989,13 @@ export class NoteView extends PureComponent { )} - {window.enabledUnfinishedFeatures && ( -
- -
- )} +
+ +
Date: Tue, 19 Apr 2022 19:45:25 +0530 Subject: [PATCH 2/6] feat: add files beta check --- .../Components/NoteView/NoteView.tsx | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/Components/NoteView/NoteView.tsx b/app/assets/javascripts/Components/NoteView/NoteView.tsx index fa1daa0a345..b4a2d01f5a4 100644 --- a/app/assets/javascripts/Components/NoteView/NoteView.tsx +++ b/app/assets/javascripts/Components/NoteView/NoteView.tsx @@ -16,6 +16,8 @@ import { ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction, NoteViewController, PayloadEmitSource, + FeatureIdentifier, + FeatureStatus, } from '@standardnotes/snjs' import { debounce, isDesktopApplication } from '@/Utils' import { KeyboardModifier, KeyboardKey } from '@/Services/IOService' @@ -112,6 +114,7 @@ type State = { /** Setting to true then false will allow the main content textarea to be destroyed * then re-initialized. Used when reloading spellcheck status. */ textareaUnloading: boolean + isEntitledToFilesBeta: boolean leftResizerWidth: number leftResizerOffset: number @@ -154,6 +157,10 @@ export class NoteView extends PureComponent { this.textAreaChangeDebounceSave = debounce(this.textAreaChangeDebounceSave, TEXTAREA_DEBOUNCE) + const isEntitledToFilesBeta = + this.application.features.getFeatureStatus(FeatureIdentifier.FilesBeta) === + FeatureStatus.Entitled + this.state = { availableStackComponents: [], editorStateDidLoad: false, @@ -173,6 +180,7 @@ export class NoteView extends PureComponent { leftResizerOffset: 0, rightResizerWidth: 0, rightResizerOffset: 0, + isEntitledToFilesBeta, } this.editorContentRef = createRef() @@ -989,13 +997,15 @@ export class NoteView extends PureComponent { )}
-
- -
+ {(window.enabledUnfinishedFeatures || this.state.isEntitledToFilesBeta) && ( +
+ +
+ )}
Date: Tue, 19 Apr 2022 21:58:37 +0530 Subject: [PATCH 3/6] feat: use centralized features state for files beta check --- .../AttachedFilesPopover/AttachedFilesButton.tsx | 16 +++------------- .../javascripts/Components/NoteView/NoteView.tsx | 10 +--------- .../UIModels/AppState/FeaturesState.ts | 13 +++++++++++++ 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx index 746ae0654e8..8067416b271 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx @@ -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' @@ -79,11 +73,7 @@ export const AttachedFilesButton: FunctionComponent = observer( }, [application, reloadAttachedFilesCount]) const toggleAttachedFilesMenu = useCallback(async () => { - if ( - !isDev && - application.features.getFeatureStatus(FeatureIdentifier.FilesBeta) !== - FeatureStatus.Entitled - ) { + if (!isDev && appState.features.hasFilesBeta) { premiumModal.activate('Files') return } @@ -110,7 +100,7 @@ export const AttachedFilesButton: FunctionComponent = observer( setOpen(newOpenState) } - }, [application.features, onClickPreprocessing, open, premiumModal]) + }, [appState.features.hasFilesBeta, onClickPreprocessing, open, premiumModal]) const deleteFile = async (file: SNFile) => { const shouldDelete = await confirmDialog({ diff --git a/app/assets/javascripts/Components/NoteView/NoteView.tsx b/app/assets/javascripts/Components/NoteView/NoteView.tsx index b4a2d01f5a4..e5be5007163 100644 --- a/app/assets/javascripts/Components/NoteView/NoteView.tsx +++ b/app/assets/javascripts/Components/NoteView/NoteView.tsx @@ -16,8 +16,6 @@ import { ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction, NoteViewController, PayloadEmitSource, - FeatureIdentifier, - FeatureStatus, } from '@standardnotes/snjs' import { debounce, isDesktopApplication } from '@/Utils' import { KeyboardModifier, KeyboardKey } from '@/Services/IOService' @@ -114,7 +112,6 @@ type State = { /** Setting to true then false will allow the main content textarea to be destroyed * then re-initialized. Used when reloading spellcheck status. */ textareaUnloading: boolean - isEntitledToFilesBeta: boolean leftResizerWidth: number leftResizerOffset: number @@ -157,10 +154,6 @@ export class NoteView extends PureComponent { this.textAreaChangeDebounceSave = debounce(this.textAreaChangeDebounceSave, TEXTAREA_DEBOUNCE) - const isEntitledToFilesBeta = - this.application.features.getFeatureStatus(FeatureIdentifier.FilesBeta) === - FeatureStatus.Entitled - this.state = { availableStackComponents: [], editorStateDidLoad: false, @@ -180,7 +173,6 @@ export class NoteView extends PureComponent { leftResizerOffset: 0, rightResizerWidth: 0, rightResizerOffset: 0, - isEntitledToFilesBeta, } this.editorContentRef = createRef() @@ -997,7 +989,7 @@ export class NoteView extends PureComponent { )}
- {(window.enabledUnfinishedFeatures || this.state.isEntitledToFilesBeta) && ( + {(window.enabledUnfinishedFeatures || this.appState.features.hasFilesBeta) && (
void @@ -23,6 +24,7 @@ export class FeaturesState { constructor(private application: WebApplication) { this._hasFolders = this.hasNativeFolders() this._hasSmartViews = this.hasNativeSmartViews() + this._hasFilesBeta = this.isEntitledToFilesBeta() this._premiumAlertFeatureName = undefined makeObservable(this, { @@ -44,6 +46,7 @@ export class FeaturesState { runInAction(() => { this._hasFolders = this.hasNativeFolders() this._hasSmartViews = this.hasNativeSmartViews() + this._hasFilesBeta = this.isEntitledToFilesBeta() }) break default: @@ -64,6 +67,10 @@ export class FeaturesState { return this._hasSmartViews } + public get hasFilesBeta(): boolean { + return this._hasFilesBeta + } + public async showPremiumAlert(featureName: string): Promise { this._premiumAlertFeatureName = featureName return when(() => this._premiumAlertFeatureName === undefined) @@ -84,4 +91,10 @@ export class FeaturesState { return status === FeatureStatus.Entitled } + + private isEntitledToFilesBeta(): boolean { + const status = this.application.features.getFeatureStatus(FeatureIdentifier.FilesBeta) + + return status === FeatureStatus.Entitled + } } From 8572b784a70b12e7a45d9a54c0e226a6991759a8 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Tue, 19 Apr 2022 22:04:19 +0530 Subject: [PATCH 4/6] feat: move extra logic to central state --- .../Components/AttachedFilesPopover/AttachedFilesButton.tsx | 3 +-- app/assets/javascripts/Components/NoteView/NoteView.tsx | 2 +- app/assets/javascripts/UIModels/AppState/FeaturesState.ts | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx index 8067416b271..427b6344f99 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx @@ -15,7 +15,6 @@ import { StreamingFileReader } from '@standardnotes/filepicker' import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' import { AttachedFilesPopover, PopoverTabs } from './AttachedFilesPopover' import { usePremiumModal } from '@/Hooks/usePremiumModal' -import { isDev } from '@/Utils' type Props = { application: WebApplication @@ -73,7 +72,7 @@ export const AttachedFilesButton: FunctionComponent = observer( }, [application, reloadAttachedFilesCount]) const toggleAttachedFilesMenu = useCallback(async () => { - if (!isDev && appState.features.hasFilesBeta) { + if (!appState.features.hasFilesBeta) { premiumModal.activate('Files') return } diff --git a/app/assets/javascripts/Components/NoteView/NoteView.tsx b/app/assets/javascripts/Components/NoteView/NoteView.tsx index e5be5007163..05195a31c1e 100644 --- a/app/assets/javascripts/Components/NoteView/NoteView.tsx +++ b/app/assets/javascripts/Components/NoteView/NoteView.tsx @@ -989,7 +989,7 @@ export class NoteView extends PureComponent { )}
- {(window.enabledUnfinishedFeatures || this.appState.features.hasFilesBeta) && ( + {this.appState.features.hasFilesBeta && (
Date: Tue, 19 Apr 2022 22:11:42 +0530 Subject: [PATCH 5/6] refactor: early return if enabled unfinished features Co-authored-by: Mo --- app/assets/javascripts/UIModels/AppState/FeaturesState.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/UIModels/AppState/FeaturesState.ts b/app/assets/javascripts/UIModels/AppState/FeaturesState.ts index 4ea65fc1c0a..4859c5aff6a 100644 --- a/app/assets/javascripts/UIModels/AppState/FeaturesState.ts +++ b/app/assets/javascripts/UIModels/AppState/FeaturesState.ts @@ -94,8 +94,11 @@ export class FeaturesState { } private isEntitledToFilesBeta(): boolean { + if (window.enabledUnfinishedFeatures) { + return true + } + const status = this.application.features.getFeatureStatus(FeatureIdentifier.FilesBeta) - - return status === FeatureStatus.Entitled || window.enabledUnfinishedFeatures || isDev + return status === FeatureStatus.Entitled } } From e328360062895e477c1f6e7a8812f0501be018ee Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Tue, 19 Apr 2022 23:02:59 +0530 Subject: [PATCH 6/6] feat: split files check into two --- .../AttachedFilesPopover/AttachedFilesButton.tsx | 4 ++-- app/assets/javascripts/Components/NoteView/NoteView.tsx | 2 +- app/assets/javascripts/UIModels/AppState/FeaturesState.ts | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx index 427b6344f99..2f7b79da40d 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx @@ -72,7 +72,7 @@ export const AttachedFilesButton: FunctionComponent = observer( }, [application, reloadAttachedFilesCount]) const toggleAttachedFilesMenu = useCallback(async () => { - if (!appState.features.hasFilesBeta) { + if (!appState.features.isEntitledToFiles) { premiumModal.activate('Files') return } @@ -99,7 +99,7 @@ export const AttachedFilesButton: FunctionComponent = observer( setOpen(newOpenState) } - }, [appState.features.hasFilesBeta, onClickPreprocessing, open, premiumModal]) + }, [appState.features.isEntitledToFiles, onClickPreprocessing, open, premiumModal]) const deleteFile = async (file: SNFile) => { const shouldDelete = await confirmDialog({ diff --git a/app/assets/javascripts/Components/NoteView/NoteView.tsx b/app/assets/javascripts/Components/NoteView/NoteView.tsx index 05195a31c1e..77bd6bd9dff 100644 --- a/app/assets/javascripts/Components/NoteView/NoteView.tsx +++ b/app/assets/javascripts/Components/NoteView/NoteView.tsx @@ -989,7 +989,7 @@ export class NoteView extends PureComponent { )}
- {this.appState.features.hasFilesBeta && ( + {this.appState.features.isFilesEnabled && (