-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Nativize "No distraction" theme as "Focus Mode" (#758)
Co-authored-by: Mo Bitar <me@bitar.io>
- Loading branch information
1 parent
fbafc13
commit 9730006
Showing
17 changed files
with
488 additions
and
141 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/assets/javascripts/components/PremiumFeaturesModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
AlertDialog, | ||
AlertDialogDescription, | ||
AlertDialogLabel, | ||
} from '@reach/alert-dialog'; | ||
import { FunctionalComponent } from 'preact'; | ||
import { Icon } from './Icon'; | ||
import PremiumIllustration from '../../svg/il-premium.svg'; | ||
import { useRef } from 'preact/hooks'; | ||
|
||
type Props = { | ||
featureName: string; | ||
onClose: () => void; | ||
showModal: boolean; | ||
}; | ||
|
||
export const PremiumFeaturesModal: FunctionalComponent<Props> = ({ | ||
featureName, | ||
onClose, | ||
showModal, | ||
}) => { | ||
const plansButtonRef = useRef<HTMLButtonElement>(null); | ||
|
||
const onClickPlans = () => { | ||
if (window._plans_url) { | ||
window.location.assign(window._plans_url); | ||
} | ||
}; | ||
|
||
return showModal ? ( | ||
<AlertDialog leastDestructiveRef={plansButtonRef}> | ||
<div tabIndex={-1} className="sn-component"> | ||
<div | ||
tabIndex={0} | ||
className="max-w-89 bg-default rounded shadow-overlay p-4" | ||
> | ||
<AlertDialogLabel> | ||
<div className="flex justify-end p-1"> | ||
<button | ||
className="flex p-0 cursor-pointer bg-transparent border-0" | ||
onClick={onClose} | ||
aria-label="Close modal" | ||
> | ||
<Icon className="color-neutral" type="close" /> | ||
</button> | ||
</div> | ||
<div | ||
className="flex items-center justify-center p-1" | ||
aria-hidden={true} | ||
> | ||
<PremiumIllustration className="mb-2" /> | ||
</div> | ||
<div className="text-lg text-center font-bold mb-1"> | ||
Enable premium features | ||
</div> | ||
</AlertDialogLabel> | ||
<AlertDialogDescription className="text-sm text-center color-grey-1 px-4.5 mb-2"> | ||
In order to use <span className="font-semibold">{featureName}</span>{' '} | ||
and other premium features, please purchase a subscription or | ||
upgrade your current plan. | ||
</AlertDialogDescription> | ||
<div className="p-4"> | ||
<button | ||
onClick={onClickPlans} | ||
className="w-full rounded no-border py-2 font-bold bg-info color-info-contrast hover:brightness-130 focus:brightness-130 cursor-pointer" | ||
ref={plansButtonRef} | ||
> | ||
See our plans | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</AlertDialog> | ||
) : null; | ||
}; |
66 changes: 66 additions & 0 deletions
66
app/assets/javascripts/components/QuickSettingsMenu/FocusModeSwitch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { WebApplication } from '@/ui_models/application'; | ||
import { FeatureIdentifier } from '@standardnotes/features'; | ||
import { FeatureStatus } from '@standardnotes/snjs'; | ||
import { FunctionComponent } from 'preact'; | ||
import { useState } from 'preact/hooks'; | ||
import { JSXInternal } from 'preact/src/jsx'; | ||
import { Icon } from '../Icon'; | ||
import { PremiumFeaturesModal } from '../PremiumFeaturesModal'; | ||
import { Switch } from '../Switch'; | ||
|
||
type Props = { | ||
application: WebApplication; | ||
closeQuickSettingsMenu: () => void; | ||
focusModeEnabled: boolean; | ||
setFocusModeEnabled: (enabled: boolean) => void; | ||
}; | ||
|
||
export const FocusModeSwitch: FunctionComponent<Props> = ({ | ||
application, | ||
closeQuickSettingsMenu, | ||
focusModeEnabled, | ||
setFocusModeEnabled, | ||
}) => { | ||
const [showUpgradeModal, setShowUpgradeModal] = useState(false); | ||
const isEntitledToFocusMode = | ||
application.getFeatureStatus(FeatureIdentifier.FocusMode) === | ||
FeatureStatus.Entitled; | ||
|
||
const toggleFocusMode = ( | ||
e: JSXInternal.TargetedMouseEvent<HTMLButtonElement> | ||
) => { | ||
e.preventDefault(); | ||
if (isEntitledToFocusMode) { | ||
setFocusModeEnabled(!focusModeEnabled); | ||
closeQuickSettingsMenu(); | ||
} else { | ||
setShowUpgradeModal(true); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<button | ||
className="sn-dropdown-item focus:bg-info-backdrop focus:shadow-none justify-between" | ||
onClick={toggleFocusMode} | ||
> | ||
<div className="flex items-center"> | ||
<Icon type="menu-close" className="color-neutral mr-2" /> | ||
Focused Writing | ||
</div> | ||
{isEntitledToFocusMode ? ( | ||
<Switch className="px-0" checked={focusModeEnabled} /> | ||
) : ( | ||
<div title="Premium feature"> | ||
<Icon type="premium-feature" /> | ||
</div> | ||
)} | ||
</button> | ||
<PremiumFeaturesModal | ||
showModal={showUpgradeModal} | ||
featureName="Focus Mode" | ||
onClose={() => setShowUpgradeModal(false)} | ||
/> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.