Skip to content

Commit

Permalink
fix: circular dependencies (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol Sójko authored May 23, 2022
1 parent 51248f2 commit 0e25885
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ import { CreateAccount } from './CreateAccount'
import { ConfirmPassword } from './ConfirmPassword'
import { JSXInternal } from 'preact/src/jsx'
import { ApplicationGroup } from '@/UIModels/ApplicationGroup'

export enum AccountMenuPane {
GeneralMenu,
SignIn,
Register,
ConfirmPassword,
}
import { AccountMenuPane } from './AccountMenuPane'

type Props = {
appState: AppState
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum AccountMenuPane {
GeneralMenu,
SignIn,
Register,
ConfirmPassword,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AppState } from '@/UIModels/AppState'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
import { AccountMenuPane } from './AccountMenu'
import { AccountMenuPane } from './AccountMenuPane'
import { Button } from '@/Components/Button/Button'
import { Checkbox } from '@/Components/Checkbox/Checkbox'
import { DecoratedPasswordInput } from '@/Components/Input/DecoratedPasswordInput'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AppState } from '@/UIModels/AppState'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { StateUpdater, useCallback, useEffect, useRef, useState } from 'preact/hooks'
import { AccountMenuPane } from './AccountMenu'
import { AccountMenuPane } from './AccountMenuPane'
import { Button } from '@/Components/Button/Button'
import { DecoratedInput } from '@/Components/Input/DecoratedInput'
import { DecoratedPasswordInput } from '@/Components/Input/DecoratedPasswordInput'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { formatLastSyncDate } from '@/Components/Preferences/Panes/Account/Sync'
import { SyncQueueStrategy } from '@standardnotes/snjs'
import { STRING_GENERIC_SYNC_ERROR } from '@/Strings'
import { useCallback, useMemo, useState } from 'preact/hooks'
import { AccountMenuPane } from './AccountMenu'
import { AccountMenuPane } from './AccountMenuPane'
import { FunctionComponent } from 'preact'
import { Menu } from '@/Components/Menu/Menu'
import { MenuItem, MenuItemSeparator, MenuItemType } from '@/Components/Menu/MenuItem'
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/Components/AccountMenu/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isDev } from '@/Utils'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
import { AccountMenuPane } from './AccountMenu'
import { AccountMenuPane } from './AccountMenuPane'
import { Button } from '@/Components/Button/Button'
import { Checkbox } from '@/Components/Checkbox/Checkbox'
import { DecoratedInput } from '@/Components/Input/DecoratedInput'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Icon } from '@/Components/Icon/Icon'
import { Menu } from '@/Components/Menu/Menu'
import { MenuItem, MenuItemType } from '@/Components/Menu/MenuItem'
import {
reloadFont,
transactionForAssociateComponentWithCurrentNote,
transactionForDisassociateComponentWithCurrentNote,
} from '@/Components/NoteView/NoteView'
import { usePremiumModal } from '@/Hooks/usePremiumModal'
import { STRING_EDIT_LOCKED_ATTEMPT } from '@/Strings'
import { WebApplication } from '@/UIModels/Application'
Expand All @@ -23,6 +18,11 @@ import { useCallback, useEffect, useState } from 'preact/hooks'
import { EditorMenuItem, EditorMenuGroup } from '@/Components/NotesOptions/ChangeEditorOption'
import { createEditorMenuGroups } from './createEditorMenuGroups'
import { PLAIN_EDITOR_NAME } from '@/Constants'
import {
transactionForAssociateComponentWithCurrentNote,
transactionForDisassociateComponentWithCurrentNote,
} from '../NoteView/TransactionFunctions'
import { reloadFont } from '../NoteView/FontFunctions'

type ChangeEditorMenuProps = {
application: WebApplication
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/Components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
STRING_UPGRADE_ACCOUNT_CONFIRM_BUTTON,
} from '@/Strings'
import { alertDialog, confirmDialog } from '@/Services/AlertService'
import { AccountMenu, AccountMenuPane } from '@/Components/AccountMenu/AccountMenu'
import { AccountMenu } from '@/Components/AccountMenu/AccountMenu'
import { AppStateEvent, EventSource } from '@/UIModels/AppState'
import { Icon } from '@/Components/Icon/Icon'
import { QuickSettingsMenu } from '@/Components/QuickSettingsMenu/QuickSettingsMenu'
import { SyncResolutionMenu } from '@/Components/SyncResolutionMenu/SyncResolutionMenu'
import { Fragment } from 'preact'
import { AccountMenuPane } from '../AccountMenu/AccountMenuPane'

type Props = {
application: WebApplication
Expand Down
9 changes: 9 additions & 0 deletions app/assets/javascripts/Components/NoteView/FontFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const reloadFont = (monospaceFont?: boolean) => {
const root = document.querySelector(':root') as HTMLElement
const propertyName = '--sn-stylekit-editor-font-family'
if (monospaceFont) {
root.style.setProperty(propertyName, 'var(--sn-stylekit-monospace-font)')
} else {
root.style.setProperty(propertyName, 'var(--sn-stylekit-sans-serif-font)')
}
}
42 changes: 5 additions & 37 deletions app/assets/javascripts/Components/NoteView/NoteView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
SNNote,
ComponentArea,
PrefKey,
ComponentMutator,
ComponentViewer,
TransactionalMutation,
ItemMutator,
ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction,
NoteViewController,
PayloadEmitSource,
Expand All @@ -33,6 +30,11 @@ import { PanelSide, PanelResizer, PanelResizeType } from '@/Components/PanelResi
import { ElementIds } from '@/ElementIDs'
import { ChangeEditorButton } from '@/Components/ChangeEditor/ChangeEditorButton'
import { AttachedFilesButton } from '@/Components/AttachedFilesPopover/AttachedFilesButton'
import {
transactionForAssociateComponentWithCurrentNote,
transactionForDisassociateComponentWithCurrentNote,
} from './TransactionFunctions'
import { reloadFont } from './FontFunctions'

const MINIMUM_STATUS_DURATION = 400
const TEXTAREA_DEBOUNCE = 100
Expand All @@ -47,40 +49,6 @@ function sortAlphabetically(array: SNComponent[]): SNComponent[] {
return array.sort((a, b) => (a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1))
}

export const transactionForAssociateComponentWithCurrentNote = (component: SNComponent, note: SNNote) => {
const transaction: TransactionalMutation = {
itemUuid: component.uuid,
mutate: (m: ItemMutator) => {
const mutator = m as ComponentMutator
mutator.removeDisassociatedItemId(note.uuid)
mutator.associateWithItem(note.uuid)
},
}
return transaction
}

export const transactionForDisassociateComponentWithCurrentNote = (component: SNComponent, note: SNNote) => {
const transaction: TransactionalMutation = {
itemUuid: component.uuid,
mutate: (m: ItemMutator) => {
const mutator = m as ComponentMutator
mutator.removeAssociatedItemId(note.uuid)
mutator.disassociateWithItem(note.uuid)
},
}
return transaction
}

export const reloadFont = (monospaceFont?: boolean) => {
const root = document.querySelector(':root') as HTMLElement
const propertyName = '--sn-stylekit-editor-font-family'
if (monospaceFont) {
root.style.setProperty(propertyName, 'var(--sn-stylekit-monospace-font)')
} else {
root.style.setProperty(propertyName, 'var(--sn-stylekit-sans-serif-font)')
}
}

type State = {
availableStackComponents: SNComponent[]
editorComponentViewer?: ComponentViewer
Expand Down
25 changes: 25 additions & 0 deletions app/assets/javascripts/Components/NoteView/TransactionFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SNComponent, SNNote, ComponentMutator, TransactionalMutation, ItemMutator } from '@standardnotes/snjs'

export const transactionForAssociateComponentWithCurrentNote = (component: SNComponent, note: SNNote) => {
const transaction: TransactionalMutation = {
itemUuid: component.uuid,
mutate: (m: ItemMutator) => {
const mutator = m as ComponentMutator
mutator.removeDisassociatedItemId(note.uuid)
mutator.associateWithItem(note.uuid)
},
}
return transaction
}

export const transactionForDisassociateComponentWithCurrentNote = (component: SNComponent, note: SNNote) => {
const transaction: TransactionalMutation = {
itemUuid: component.uuid,
mutate: (m: ItemMutator) => {
const mutator = m as ComponentMutator
mutator.removeAssociatedItemId(note.uuid)
mutator.disassociateWithItem(note.uuid)
},
}
return transaction
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenu'
import { Button } from '@/Components/Button/Button'
import { PreferencesGroup, PreferencesSegment, Text, Title } from '@/Components/Preferences/PreferencesComponents'
import { WebApplication } from '@/UIModels/Application'
import { AppState } from '@/UIModels/AppState'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { AccountIllustration } from '@standardnotes/icons'
import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane'

export const Authentication: FunctionComponent<{
application: WebApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LinkButton, Text } from '@/Components/Preferences/PreferencesComponents
import { Button } from '@/Components/Button/Button'
import { WebApplication } from '@/UIModels/Application'
import { useState } from 'preact/hooks'
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowWrapper'
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowFunctions'

export const NoSubscription: FunctionalComponent<{
application: WebApplication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Button } from '@/Components/Button/Button'
import { WebApplication } from '@/UIModels/Application'
import { AppState } from '@/UIModels/AppState'
import { PurchaseFlowPane } from '@/UIModels/AppState/PurchaseFlowState'
import { PurchaseFlowPane } from '@/UIModels/AppState/PurchaseFlowPane'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { useEffect, useRef, useState } from 'preact/hooks'
import { FloatingLabelInput } from '@/Components/Input/FloatingLabelInput'
import { isEmailValid } from '@/Utils'
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowWrapper'
import { BlueDotIcon, CircleIcon, DiamondIcon, CreateAccountIllustration } from '@standardnotes/icons'
import { loadPurchaseFlowUrl } from '../PurchaseFlowFunctions'

type Props = {
appState: AppState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Button } from '@/Components/Button/Button'
import { WebApplication } from '@/UIModels/Application'
import { AppState } from '@/UIModels/AppState'
import { PurchaseFlowPane } from '@/UIModels/AppState/PurchaseFlowState'
import { PurchaseFlowPane } from '@/UIModels/AppState/PurchaseFlowPane'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { useEffect, useRef, useState } from 'preact/hooks'
import { FloatingLabelInput } from '@/Components/Input/FloatingLabelInput'
import { isEmailValid } from '@/Utils'
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowWrapper'
import { BlueDotIcon, CircleIcon, DiamondIcon } from '@standardnotes/icons'
import { loadPurchaseFlowUrl } from '../PurchaseFlowFunctions'

type Props = {
appState: AppState
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { WebApplication } from '@/UIModels/Application'
import { getWindowUrlParams, isDesktopApplication } from '@/Utils'

export const getPurchaseFlowUrl = async (application: WebApplication): Promise<string | undefined> => {
const currentUrl = window.location.origin
const successUrl = isDesktopApplication() ? 'standardnotes://' : currentUrl
if (application.noAccount()) {
return `${window.purchaseUrl}/offline?&success_url=${successUrl}`
}
const token = await application.getNewSubscriptionToken()
if (token) {
return `${window.purchaseUrl}?subscription_token=${token}&success_url=${successUrl}`
}
return undefined
}

export const loadPurchaseFlowUrl = async (application: WebApplication): Promise<boolean> => {
const url = await getPurchaseFlowUrl(application)
const params = getWindowUrlParams()
const period = params.get('period') ? `&period=${params.get('period')}` : ''
const plan = params.get('plan') ? `&plan=${params.get('plan')}` : ''
if (url) {
window.location.assign(`${url}${period}${plan}`)
return true
}
return false
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WebApplication } from '@/UIModels/Application'
import { AppState } from '@/UIModels/AppState'
import { PurchaseFlowPane } from '@/UIModels/AppState/PurchaseFlowState'
import { PurchaseFlowPane } from '@/UIModels/AppState/PurchaseFlowPane'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { CreateAccount } from './Panes/CreateAccount'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { WebApplication } from '@/UIModels/Application'
import { AppState } from '@/UIModels/AppState'
import { getWindowUrlParams, isDesktopApplication } from '@/Utils'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { PurchaseFlowView } from './PurchaseFlowView'
Expand All @@ -10,31 +9,6 @@ export type PurchaseFlowWrapperProps = {
application: WebApplication
}

export const getPurchaseFlowUrl = async (application: WebApplication): Promise<string | undefined> => {
const currentUrl = window.location.origin
const successUrl = isDesktopApplication() ? 'standardnotes://' : currentUrl
if (application.noAccount()) {
return `${window.purchaseUrl}/offline?&success_url=${successUrl}`
}
const token = await application.getNewSubscriptionToken()
if (token) {
return `${window.purchaseUrl}?subscription_token=${token}&success_url=${successUrl}`
}
return undefined
}

export const loadPurchaseFlowUrl = async (application: WebApplication): Promise<boolean> => {
const url = await getPurchaseFlowUrl(application)
const params = getWindowUrlParams()
const period = params.get('period') ? `&period=${params.get('period')}` : ''
const plan = params.get('plan') ? `&plan=${params.get('plan')}` : ''
if (url) {
window.location.assign(`${url}${period}${plan}`)
return true
}
return false
}

export const PurchaseFlowWrapper: FunctionComponent<PurchaseFlowWrapperProps> = observer(
({ appState, application }) => {
if (!appState.purchaseFlow.isOpen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { destroyAllObjectProperties, isDev } from '@/Utils'
import { action, computed, makeObservable, observable, runInAction } from 'mobx'
import { ApplicationEvent, ContentType, DeinitSource, SNNote, SNTag } from '@standardnotes/snjs'
import { WebApplication } from '@/UIModels/Application'
import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenu'
import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane'
import { AbstractState } from './AbstractState'

type StructuredItemsCount = {
Expand Down
12 changes: 1 addition & 11 deletions app/assets/javascripts/UIModels/AppState/AppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,7 @@ import { FilePreviewModalState } from './FilePreviewModalState'
import { AbstractState } from './AbstractState'
import { SelectedItemsState } from './SelectedItemsState'
import { ListableContentItem } from '@/Components/ContentListView/Types/ListableContentItem'

export enum AppStateEvent {
TagChanged,
ActiveEditorChanged,
PanelResized,
EditorFocused,
BeganBackupDownload,
EndedBackupDownload,
WindowDidFocus,
WindowDidBlur,
}
import { AppStateEvent } from './AppStateEvent'

export type PanelResizedData = {
panel: string
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/UIModels/AppState/AppStateEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum AppStateEvent {
TagChanged,
ActiveEditorChanged,
PanelResized,
EditorFocused,
BeganBackupDownload,
EndedBackupDownload,
WindowDidFocus,
WindowDidBlur,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
DisplayOptions,
} from '@standardnotes/snjs'
import { action, computed, makeObservable, observable, reaction, runInAction } from 'mobx'
import { AppState, AppStateEvent } from '.'
import { WebApplication } from '../Application'
import { AbstractState } from './AbstractState'
import { AppState } from './AppState'
import { AppStateEvent } from './AppStateEvent'
import { WebDisplayOptions } from './WebDisplayOptions'

const MinNoteCellHeight = 51.0
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/UIModels/AppState/PurchaseFlowPane.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum PurchaseFlowPane {
SignIn,
CreateAccount,
}
8 changes: 2 additions & 6 deletions app/assets/javascripts/UIModels/AppState/PurchaseFlowState.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowWrapper'
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowFunctions'
import { action, makeObservable, observable } from 'mobx'
import { WebApplication } from '../Application'
import { AbstractState } from './AbstractState'

export enum PurchaseFlowPane {
SignIn,
CreateAccount,
}
import { PurchaseFlowPane } from './PurchaseFlowPane'

export class PurchaseFlowState extends AbstractState {
isOpen = false
Expand Down
Loading

0 comments on commit 0e25885

Please sign in to comment.