-
Notifications
You must be signed in to change notification settings - Fork 373
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
Add tooltips to the note detail toolbar #599
Changes from 6 commits
bdb9c51
dfb4a93
cdddcda
83e9f7d
ee04570
9416a0a
23be3d6
8da54f6
a7c8af8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import { mdiBookOpen, mdiSlashForward } from '@mdi/js' | |
import Icon from '../atoms/Icon' | ||
import { useRouter, useRouteParams } from '../../lib/router' | ||
import { flexCenter } from '../../lib/styled/styleFunctions' | ||
import { useTranslation } from 'react-i18next' | ||
import { useDb } from '../../lib/db' | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
|
@@ -21,7 +23,7 @@ const IconContainer = styled.div` | |
color: ${({ theme }) => theme.navButtonColor}; | ||
` | ||
|
||
const FolderNavItem = styled.button` | ||
const FolderNavItemButton = styled.button` | ||
background-color: transparent; | ||
border: none; | ||
white-space: nowrap; | ||
|
@@ -54,12 +56,17 @@ interface FolderData { | |
pathname: string | ||
} | ||
|
||
const NoteDetailFolderNavigator = ({ | ||
storageId, | ||
storageName, | ||
noteId, | ||
noteFolderPathname, | ||
}: NoteDetailFolderNavigatorProps) => { | ||
interface FolderNavItemProps { | ||
path: string | ||
children?: React.ReactNode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not accept children |
||
} | ||
|
||
const FolderNavItem: React.FC<FolderNavItemProps> = ({ | ||
children, | ||
path, | ||
}: FolderNavItemProps) => { | ||
const { t } = useTranslation() | ||
const db = useDb() | ||
const { push } = useRouter() | ||
const routeParams = useRouteParams() | ||
|
||
|
@@ -70,6 +77,70 @@ const NoteDetailFolderNavigator = ({ | |
return routeParams.folderPathname | ||
}, [routeParams]) | ||
|
||
const parsePath = (path: string) => { | ||
const result = { | ||
storageId: '', | ||
storageName: '', | ||
folderName: '', | ||
folderPath: '', | ||
} | ||
|
||
const storageMatch = /\/storages\/(.*)\/notes/.exec(path) | ||
if (storageMatch) { | ||
const storage = db.storageMap[storageMatch[1]] | ||
if (storage) { | ||
result.storageId = storage.id | ||
result.storageName = storage.name | ||
} | ||
} | ||
const folderMatch = /\/notes\/(.*)\//.exec(path) | ||
if (folderMatch) { | ||
result.folderPath = `/${folderMatch[1]}` | ||
|
||
const folderNameMatch = /[^/]*$/.exec(result.folderPath) | ||
if (folderNameMatch) { | ||
result.folderName = folderNameMatch[0] | ||
} | ||
} | ||
return result | ||
} | ||
|
||
const { storageName, folderName, folderPath } = parsePath(path) | ||
const getStorageTooltip = (storageName: string) => | ||
`${t('storage.storage')} ${storageName}: ${t('general.allnote')}` | ||
|
||
const getFolderTooltip = (foldername: string) => | ||
`${t('folder.folder')} ${foldername}: ${t('general.allnote')}` | ||
|
||
const tooltip = folderName | ||
? getFolderTooltip(folderName) | ||
: getStorageTooltip(storageName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a folder nav item, not a storage item. |
||
|
||
const isActive = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
currentFolderPathname === folderPath || | ||
(!folderName && currentFolderPathname === '/') | ||
|
||
return ( | ||
<FolderNavItemButton | ||
title={tooltip} | ||
href={path} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a button, not an anchor element |
||
onClick={(event: MouseEvent<HTMLAnchorElement>) => { | ||
event.preventDefault() | ||
push(path) | ||
}} | ||
className={isActive ? 'active' : ''} | ||
> | ||
{folderName ? folderName : storageName} | ||
{children} | ||
</FolderNavItemButton> | ||
) | ||
} | ||
|
||
const NoteDetailFolderNavigator = ({ | ||
storageId, | ||
noteId, | ||
noteFolderPathname, | ||
}: NoteDetailFolderNavigatorProps) => { | ||
const folderDataList = useMemo<FolderData[]>(() => { | ||
if (noteFolderPathname === '/') { | ||
return [] | ||
|
@@ -92,31 +163,14 @@ const NoteDetailFolderNavigator = ({ | |
<IconContainer> | ||
<Icon path={mdiBookOpen} /> | ||
</IconContainer> | ||
<FolderNavItem | ||
href={`/app/storages/${storageId}/notes/${noteId}`} | ||
onClick={(event: MouseEvent<HTMLAnchorElement>) => { | ||
event.preventDefault() | ||
push(`/app/storages/${storageId}/notes/${noteId}`) | ||
}} | ||
className={currentFolderPathname === '/' ? 'active' : ''} | ||
> | ||
{storageName} | ||
</FolderNavItem> | ||
<FolderNavItem path={`/app/storages/${storageId}/notes/${noteId}`} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to introduce another component |
||
|
||
{folderDataList.map((folderData) => ( | ||
<React.Fragment key={folderData.pathname}> | ||
<Icon path={mdiSlashForward} /> | ||
<FolderNavItem | ||
onClick={() => { | ||
push( | ||
`/app/storages/${storageId}/notes${folderData.pathname}/${noteId}` | ||
) | ||
}} | ||
className={ | ||
currentFolderPathname === folderData.pathname ? 'active' : '' | ||
} | ||
> | ||
{folderData.name} | ||
</FolderNavItem> | ||
path={`/app/storages/${storageId}/notes${folderData.pathname}/${noteId}`} | ||
/> | ||
</React.Fragment> | ||
))} | ||
</Container> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storageId, storageName, noteId, noteFolderPathname are already resolved from parent component. We don't need to parse again. It will make our app slower.