feat: upload prompt on add button click in FilesView (#1053)
This commit is contained in:
@@ -2,7 +2,7 @@ import { KeyboardKey, KeyboardModifier } from '@/Services/IOService'
|
|||||||
import { WebApplication } from '@/UIModels/Application'
|
import { WebApplication } from '@/UIModels/Application'
|
||||||
import { AppState } from '@/UIModels/AppState'
|
import { AppState } from '@/UIModels/AppState'
|
||||||
import { PANEL_NAME_NOTES } from '@/Constants'
|
import { PANEL_NAME_NOTES } from '@/Constants'
|
||||||
import { PrefKey } from '@standardnotes/snjs'
|
import { PrefKey, SystemViewId } from '@standardnotes/snjs'
|
||||||
import { observer } from 'mobx-react-lite'
|
import { observer } from 'mobx-react-lite'
|
||||||
import {
|
import {
|
||||||
ChangeEventHandler,
|
ChangeEventHandler,
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
KeyboardEventHandler,
|
KeyboardEventHandler,
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
@@ -54,6 +55,19 @@ const ContentListView: FunctionComponent<Props> = ({ application, appState }) =>
|
|||||||
|
|
||||||
const [closeDisplayOptMenuOnBlur] = useCloseOnBlur(displayOptionsMenuRef, setShowDisplayOptionsMenu)
|
const [closeDisplayOptMenuOnBlur] = useCloseOnBlur(displayOptionsMenuRef, setShowDisplayOptionsMenu)
|
||||||
|
|
||||||
|
const isFilesSmartView = useMemo(
|
||||||
|
() => appState.tags.selected?.uuid === SystemViewId.Files,
|
||||||
|
[appState.tags.selected?.uuid],
|
||||||
|
)
|
||||||
|
|
||||||
|
const addNewItem = useCallback(() => {
|
||||||
|
if (isFilesSmartView) {
|
||||||
|
void appState.files.uploadNewFile()
|
||||||
|
} else {
|
||||||
|
void createNewNote()
|
||||||
|
}
|
||||||
|
}, [appState.files, createNewNote, isFilesSmartView])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
/**
|
/**
|
||||||
* In the browser we're not allowed to override cmd/ctrl + n, so we have to
|
* In the browser we're not allowed to override cmd/ctrl + n, so we have to
|
||||||
@@ -65,7 +79,7 @@ const ContentListView: FunctionComponent<Props> = ({ application, appState }) =>
|
|||||||
modifiers: [KeyboardModifier.Meta, KeyboardModifier.Ctrl],
|
modifiers: [KeyboardModifier.Meta, KeyboardModifier.Ctrl],
|
||||||
onKeyDown: (event) => {
|
onKeyDown: (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
void createNewNote()
|
addNewItem()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -104,7 +118,7 @@ const ContentListView: FunctionComponent<Props> = ({ application, appState }) =>
|
|||||||
previousNoteKeyObserver()
|
previousNoteKeyObserver()
|
||||||
searchKeyObserver()
|
searchKeyObserver()
|
||||||
}
|
}
|
||||||
}, [application.io, createNewNote, searchBarElement, selectNextItem, selectPreviousItem])
|
}, [addNewItem, application.io, createNewNote, searchBarElement, selectNextItem, selectPreviousItem])
|
||||||
|
|
||||||
const onNoteFilterTextChange: ChangeEventHandler<HTMLInputElement> = useCallback(
|
const onNoteFilterTextChange: ChangeEventHandler<HTMLInputElement> = useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
@@ -142,6 +156,11 @@ const ContentListView: FunctionComponent<Props> = ({ application, appState }) =>
|
|||||||
setShowDisplayOptionsMenu(!showDisplayOptionsMenu)
|
setShowDisplayOptionsMenu(!showDisplayOptionsMenu)
|
||||||
}, [showDisplayOptionsMenu])
|
}, [showDisplayOptionsMenu])
|
||||||
|
|
||||||
|
const addButtonLabel = useMemo(
|
||||||
|
() => (isFilesSmartView ? 'Upload file' : 'Create a new note in the selected tag'),
|
||||||
|
[isFilesSmartView],
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id="items-column"
|
id="items-column"
|
||||||
@@ -156,9 +175,9 @@ const ContentListView: FunctionComponent<Props> = ({ application, appState }) =>
|
|||||||
<div className="sk-h2 font-semibold title">{panelTitle}</div>
|
<div className="sk-h2 font-semibold title">{panelTitle}</div>
|
||||||
<button
|
<button
|
||||||
className="sk-button contrast wide"
|
className="sk-button contrast wide"
|
||||||
title="Create a new note in the selected tag"
|
title={addButtonLabel}
|
||||||
aria-label="Create new note"
|
aria-label={addButtonLabel}
|
||||||
onClick={() => createNewNote()}
|
onClick={addNewItem}
|
||||||
>
|
>
|
||||||
<div className="sk-label">
|
<div className="sk-label">
|
||||||
<i className="ion-plus add-button" aria-hidden></i>
|
<i className="ion-plus add-button" aria-hidden></i>
|
||||||
|
|||||||
Reference in New Issue
Block a user