Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 2 additions & 48 deletions packages/web/src/javascripts/Components/Tags/TagsSection.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,13 @@
import TagsList from '@/Components/Tags/TagsList'
import { ApplicationEvent } from '@/__mocks__/@standardnotes/snjs'
import { observer } from 'mobx-react-lite'
import { FunctionComponent, useCallback, useEffect, useState } from 'react'
import { FunctionComponent } from 'react'
import TagsSectionAddButton from './TagsSectionAddButton'
import TagsSectionTitle from './TagsSectionTitle'
import { useApplication } from '../ApplicationProvider'

const TagsSection: FunctionComponent = () => {
const application = useApplication()

const [hasMigration, setHasMigration] = useState<boolean>(false)

const checkIfMigrationNeeded = useCallback(() => {
setHasMigration(application.items.hasTagsNeedingFoldersMigration())
}, [application])

useEffect(() => {
const removeObserver = application.addEventObserver(async (event) => {
const events = [ApplicationEvent.CompletedInitialSync, ApplicationEvent.SignedIn]
if (events.includes(event)) {
checkIfMigrationNeeded()
}
})

return () => {
removeObserver()
}
}, [application, checkIfMigrationNeeded])

const runMigration = useCallback(async () => {
if (
await application.alerts.confirm(
'<i>Introducing native, built-in nested tags without requiring the legacy Folders extension.</i><br/></br> ' +
" To get started, we'll need to migrate any tags containing a dot character to the new system.<br/></br> " +
' This migration will convert any tags with dots appearing in their name into a natural' +
' hierarchy that is compatible with the new nested tags feature.' +
' Running this migration will remove any "." characters appearing in tag names.',
'New: Folders to Nested Tags',
'Run Migration',
)
) {
application.mutator
.migrateTagsToFolders()
.then(() => {
void application.sync.sync()
checkIfMigrationNeeded()
})
.catch(console.error)
}
}, [application, checkIfMigrationNeeded])

return (
<>
{application.navigationController.starredTags.length > 0 && (
Expand All @@ -68,11 +26,7 @@ const TagsSection: FunctionComponent = () => {
<section>
<div className={'section-title-bar'}>
<div className="section-title-bar-header">
<TagsSectionTitle
features={application.featuresController}
hasMigration={hasMigration}
onClickMigration={runMigration}
/>
<TagsSectionTitle features={application.featuresController} />
{!application.navigationController.isSearching && (
<TagsSectionAddButton tags={application.navigationController} features={application.featuresController} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import StyledTooltip from '../StyledTooltip/StyledTooltip'

type Props = {
features: FeaturesController
hasMigration: boolean
onClickMigration: () => void
}

const TagsSectionTitle: FunctionComponent<Props> = ({ features, hasMigration, onClickMigration }) => {
const TagsSectionTitle: FunctionComponent<Props> = ({ features }) => {
const entitledToFolders = features.hasFolders
const modal = usePremiumModal()

Expand All @@ -24,11 +22,6 @@ const TagsSectionTitle: FunctionComponent<Props> = ({ features, hasMigration, on
<>
<div className="title text-base md:text-sm">
<span className="font-bold">Folders</span>
{hasMigration && (
<label className="ml-1 cursor-pointer font-bold text-info" onClick={onClickMigration}>
Migration Available
</label>
)}
</div>
</>
)
Expand Down
Loading