refactor: rename states to view controllers (#1060)

This commit is contained in:
Mo
2022-06-01 10:15:45 -05:00
committed by GitHub
parent 78f39ec85d
commit 54125cec21
177 changed files with 1518 additions and 1365 deletions

View File

@@ -1,5 +1,5 @@
import { WebApplication } from '@/UIModels/Application'
import { AppState } from '@/UIModels/AppState'
import { WebApplication } from '@/Application/Application'
import { ViewControllerManager } from '@/Services/ViewControllerManager'
import { MENU_MARGIN_FROM_APP_BORDER } from '@/Constants'
import { Disclosure, DisclosureButton, DisclosurePanel } from '@reach/disclosure'
import VisuallyHidden from '@reach/visually-hidden'
@@ -19,13 +19,17 @@ import { isHandlingFileDrag } from '@/Utils/DragTypeCheck'
type Props = {
application: WebApplication
appState: AppState
viewControllerManager: ViewControllerManager
onClickPreprocessing?: () => Promise<void>
}
const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState, onClickPreprocessing }: Props) => {
const AttachedFilesButton: FunctionComponent<Props> = ({
application,
viewControllerManager,
onClickPreprocessing,
}: Props) => {
const premiumModal = usePremiumModal()
const note: SNNote | undefined = appState.notes.firstSelectedNote
const note: SNNote | undefined = viewControllerManager.notesController.firstSelectedNote
const [open, setOpen] = useState(false)
const [position, setPosition] = useState({
@@ -39,12 +43,12 @@ const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState,
const [closeOnBlur, keepMenuOpen] = useCloseOnBlur(containerRef, setOpen)
useEffect(() => {
if (appState.filePreviewModal.isOpen) {
if (viewControllerManager.filePreviewModalController.isOpen) {
keepMenuOpen(true)
} else {
keepMenuOpen(false)
}
}, [appState.filePreviewModal.isOpen, keepMenuOpen])
}, [viewControllerManager.filePreviewModalController.isOpen, keepMenuOpen])
const [currentTab, setCurrentTab] = useState(PopoverTabs.AttachedFiles)
const [allFiles, setAllFiles] = useState<FileItem[]>([])
@@ -90,10 +94,10 @@ const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState,
}, [onClickPreprocessing, open])
const prospectivelyShowFilesPremiumModal = useCallback(() => {
if (!appState.features.hasFiles) {
if (!viewControllerManager.featuresController.hasFiles) {
premiumModal.activate('Files')
}
}, [appState.features.hasFiles, premiumModal])
}, [viewControllerManager.featuresController.hasFiles, premiumModal])
const toggleAttachedFilesMenuWithEntitlementCheck = useCallback(async () => {
prospectivelyShowFilesPremiumModal()
@@ -121,7 +125,7 @@ const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState,
}
const downloadFile = async (file: FileItem) => {
appState.files.downloadFile(file).catch(console.error)
viewControllerManager.filesController.downloadFile(file).catch(console.error)
}
const attachFileToNote = useCallback(
@@ -213,7 +217,7 @@ const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState,
case PopoverFileItemActionType.PreviewFile: {
keepMenuOpen(true)
const otherFiles = currentTab === PopoverTabs.AllFiles ? allFiles : attachedFiles
appState.filePreviewModal.activate(
viewControllerManager.filePreviewModalController.activate(
file,
otherFiles.filter((file) => !file.protected),
)
@@ -305,7 +309,7 @@ const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState,
setIsDraggingFiles(false)
if (!appState.features.hasFiles) {
if (!viewControllerManager.featuresController.hasFiles) {
prospectivelyShowFilesPremiumModal()
return
}
@@ -320,7 +324,7 @@ const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState,
return
}
const uploadedFiles = await appState.files.uploadNewFile(fileOrHandle)
const uploadedFiles = await viewControllerManager.filesController.uploadNewFile(fileOrHandle)
if (!uploadedFiles) {
return
@@ -338,8 +342,8 @@ const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState,
}
},
[
appState.files,
appState.features.hasFiles,
viewControllerManager.filesController,
viewControllerManager.featuresController.hasFiles,
attachFileToNote,
currentTab,
application,
@@ -396,7 +400,7 @@ const AttachedFilesButton: FunctionComponent<Props> = ({ application, appState,
{open && (
<AttachedFilesPopover
application={application}
appState={appState}
viewControllerManager={viewControllerManager}
attachedFiles={attachedFiles}
allFiles={allFiles}
closeOnBlur={closeOnBlur}

View File

@@ -1,6 +1,6 @@
import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants'
import { WebApplication } from '@/UIModels/Application'
import { AppState } from '@/UIModels/AppState'
import { WebApplication } from '@/Application/Application'
import { ViewControllerManager } from '@/Services/ViewControllerManager'
import { FileItem } from '@standardnotes/snjs'
import { FilesIllustration } from '@standardnotes/icons'
import { observer } from 'mobx-react-lite'
@@ -13,7 +13,7 @@ import { PopoverTabs } from './PopoverTabs'
type Props = {
application: WebApplication
appState: AppState
viewControllerManager: ViewControllerManager
allFiles: FileItem[]
attachedFiles: FileItem[]
closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void
@@ -25,7 +25,7 @@ type Props = {
const AttachedFilesPopover: FunctionComponent<Props> = ({
application,
appState,
viewControllerManager,
allFiles,
attachedFiles,
closeOnBlur,
@@ -45,7 +45,7 @@ const AttachedFilesPopover: FunctionComponent<Props> = ({
: filesList
const handleAttachFilesClick = async () => {
const uploadedFiles = await appState.files.uploadNewFile()
const uploadedFiles = await viewControllerManager.filesController.uploadNewFile()
if (!uploadedFiles) {
return
}