Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: show toast when duplicating note and update last modified date for duplicated note #2379

Merged
merged 9 commits into from
Aug 1, 2023
7 changes: 7 additions & 0 deletions packages/snjs/lib/Services/Mutator/MutatorService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ describe('mutator service', () => {

expect(note.userModifiedDate).toEqual(pinnedNote?.userModifiedDate)
})

it('should update the modification date of duplicated notes', async () => {
const note = await insertNote('hello')
const duplicatedNote = await mutatorService.duplicateItem(note)

expect(duplicatedNote.userModifiedDate.getTime()).toBeGreaterThan(note.userModifiedDate.getTime())
})
})

describe('linking', () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/snjs/lib/Services/Mutator/MutatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { PayloadManager } from '../Payloads/PayloadManager'
import { TagsToFoldersMigrationApplicator } from '@Lib/Migrations/Applicators/TagsToFolders'
import {
ActionsExtensionMutator,
AppDataField,
ComponentInterface,
ComponentMutator,
CreateDecryptedMutatorForItem,
DecryptedItemInterface,
DecryptedItemMutator,
DecryptedPayload,
DecryptedPayloadInterface,
DefaultAppDomain,
DeleteItemMutator,
EncryptedItemInterface,
FeatureRepoMutator,
Expand Down Expand Up @@ -319,7 +321,14 @@ export class MutatorService extends AbstractService implements MutatorClientInte
payload,
baseCollection: this.payloadManager.getMasterCollection(),
isConflict,
additionalContent,
additionalContent: {
appData: {
[DefaultAppDomain]: {
[AppDataField.UserModifiedDate]: new Date(),
},
},
...additionalContent,
},
})

await this.payloadManager.emitPayloads(resultingPayloads, PayloadEmitSource.LocalChanged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ const ApplicationView: FunctionComponent<Props> = ({ application, mainApplicatio
notesController={viewControllerManager.notesController}
linkingController={viewControllerManager.linkingController}
historyModalController={viewControllerManager.historyModalController}
selectionController={viewControllerManager.selectionController}
/>
<TagContextMenuWrapper
navigationController={viewControllerManager.navigationController}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ const ContentListView = forwardRef<HTMLDivElement, Props>(
notesController={notesController}
historyModalController={historyModalController}
itemListController={itemListController}
selectionController={selectionController}
/>
) : (
<ContentList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { useItemLinks } from '@/Hooks/useItemLinks'
import { ItemLink } from '@/Utils/Items/Search/ItemLink'
import { ItemListController } from '@/Controllers/ItemList/ItemListController'
import ListItemVaultInfo from '../ContentListView/ListItemVaultInfo'
import { SelectedItemsController } from '@/Controllers/SelectedItemsController'

const ContextMenuCell = ({
items,
Expand All @@ -49,13 +50,15 @@ const ContextMenuCell = ({
linkingController,
notesController,
historyModalController,
selectionController,
}: {
items: DecryptedItemInterface[]
filesController: FilesController
navigationController: NavigationController
linkingController: LinkingController
notesController: NotesController
historyModalController: HistoryModalController
selectionController: SelectedItemsController
}) => {
const [contextMenuVisible, setContextMenuVisible] = useState(false)
const anchorElementRef = useRef<HTMLButtonElement>(null)
Expand Down Expand Up @@ -117,6 +120,7 @@ const ContextMenuCell = ({
notesController={notesController}
linkingController={linkingController}
historyModalController={historyModalController}
selectionController={selectionController}
closeMenu={() => {
setContextMenuVisible(false)
}}
Expand Down Expand Up @@ -266,6 +270,7 @@ type Props = {
notesController: NotesController
historyModalController: HistoryModalController
itemListController: ItemListController
selectionController: SelectedItemsController
}

const ContentTableView = ({
Expand All @@ -278,6 +283,7 @@ const ContentTableView = ({
notesController,
historyModalController,
itemListController,
selectionController,
}: Props) => {
const listHasFiles = items.some((item) => item instanceof FileItem)

Expand Down Expand Up @@ -406,6 +412,7 @@ const ContentTableView = ({
navigationController={navigationController}
notesController={notesController}
historyModalController={historyModalController}
selectionController={selectionController}
/>
</div>
)
Expand All @@ -418,6 +425,7 @@ const ContentTableView = ({
navigationController={navigationController}
notesController={notesController}
historyModalController={historyModalController}
selectionController={selectionController}
/>
),
showSelectionActions: true,
Expand Down Expand Up @@ -465,6 +473,7 @@ const ContentTableView = ({
notesController={notesController}
linkingController={linkingController}
historyModalController={historyModalController}
selectionController={selectionController}
closeMenu={closeContextMenu}
/>
</Menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const MultipleSelectedNotes = ({
notesController={notesController}
linkingController={linkingController}
historyModalController={historyModalController}
selectionController={selectionController}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
notesController={this.viewControllerManager.notesController}
linkingController={this.viewControllerManager.linkingController}
historyModalController={this.viewControllerManager.historyModalController}
selectionController={this.viewControllerManager.selectionController}
onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import { HistoryModalController } from '@/Controllers/NoteHistory/HistoryModalCo
import Popover from '../Popover/Popover'
import { LinkingController } from '@/Controllers/LinkingController'
import Menu from '../Menu/Menu'
import { SelectedItemsController } from '@/Controllers/SelectedItemsController'

type Props = {
navigationController: NavigationController
notesController: NotesController
linkingController: LinkingController
historyModalController: HistoryModalController
selectionController: SelectedItemsController
}

const NotesContextMenu = ({
navigationController,
notesController,
linkingController,
historyModalController,
selectionController,
}: Props) => {
const { contextMenuOpen, contextMenuClickLocation, setContextMenuOpen } = notesController

Expand Down Expand Up @@ -50,6 +53,7 @@ const NotesContextMenu = ({
notesController={notesController}
linkingController={linkingController}
historyModalController={historyModalController}
selectionController={selectionController}
requestDisableClickOutside={handleDisableClickOutsideRequest}
closeMenu={closeMenu}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const NotesOptions = ({
navigationController,
notesController,
linkingController,
selectionController,
historyModalController,
closeMenu,
}: NotesOptionsProps) => {
Expand Down Expand Up @@ -150,10 +151,32 @@ const NotesOptions = ({
}, [closeMenu, toggleAppPane])

const duplicateSelectedItems = useCallback(async () => {
await Promise.all(notes.map((note) => application.mutator.duplicateItem(note).catch(console.error)))
await Promise.all(
notes.map((note) =>
application.mutator
.duplicateItem(note)
.then((duplicated) =>
addToast({
type: ToastType.Regular,
message: `Duplicated note "${duplicated.title}"`,
actions: [
{
label: 'Open',
handler: (toastId) => {
selectionController.selectItem(duplicated.uuid, true).catch(console.error)
dismissToast(toastId)
},
},
],
autoClose: true,
}),
)
.catch(console.error),
),
)
void application.sync.sync()
closeMenuAndToggleNotesList()
}, [application.mutator, application.sync, closeMenuAndToggleNotesList, notes])
}, [application.mutator, application.sync, closeMenuAndToggleNotesList, notes, selectionController])

const openRevisionHistoryModal = useCallback(() => {
historyModalController.openModal(notesController.firstSelectedNote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import Popover from '../Popover/Popover'
import { LinkingController } from '@/Controllers/LinkingController'
import RoundIconButton from '../Button/RoundIconButton'
import Menu from '../Menu/Menu'
import { SelectedItemsController } from '@/Controllers/SelectedItemsController'

type Props = {
navigationController: NavigationController
notesController: NotesController
linkingController: LinkingController
historyModalController: HistoryModalController
selectionController: SelectedItemsController
onClickPreprocessing?: () => Promise<void>
}

Expand All @@ -22,6 +24,7 @@ const NotesOptionsPanel = ({
notesController,
linkingController,
historyModalController,
selectionController,
onClickPreprocessing,
}: Props) => {
const [isOpen, setIsOpen] = useState(false)
Expand Down Expand Up @@ -58,6 +61,7 @@ const NotesOptionsPanel = ({
notesController={notesController}
linkingController={linkingController}
historyModalController={historyModalController}
selectionController={selectionController}
requestDisableClickOutside={handleDisableClickOutsideRequest}
closeMenu={toggleMenu}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { NavigationController } from '@/Controllers/Navigation/NavigationControl
import { NotesController } from '@/Controllers/NotesController/NotesController'
import { LinkingController } from '@/Controllers/LinkingController'
import { SNNote } from '@standardnotes/snjs'
import { SelectedItemsController } from '@/Controllers/SelectedItemsController'

export type NotesOptionsProps = {
notes: SNNote[]
navigationController: NavigationController
notesController: NotesController
linkingController: LinkingController
historyModalController: HistoryModalController
selectionController: SelectedItemsController
requestDisableClickOutside?: (disabled: boolean) => void
closeMenu: () => void
}