From a5b9fd608960ed221f072a0320668045d1ed1c01 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 2 Dec 2022 10:01:01 +0800 Subject: [PATCH 1/2] New kbar and keyboard command for opening the notebook --- .../templates/article/HighlightsModal.tsx | 2 +- .../web/pages/[username]/[slug]/index.tsx | 256 ++++++++++-------- 2 files changed, 142 insertions(+), 116 deletions(-) diff --git a/packages/web/components/templates/article/HighlightsModal.tsx b/packages/web/components/templates/article/HighlightsModal.tsx index 8336472c4..76370a261 100644 --- a/packages/web/components/templates/article/HighlightsModal.tsx +++ b/packages/web/components/templates/article/HighlightsModal.tsx @@ -112,7 +112,7 @@ function ModalHighlightView(props: ModalHighlightViewProps): JSX.Element { return ( <> - + ( () => import('./../../../components/templates/article/PdfArticleContainer'), { ssr: false } @@ -47,7 +52,7 @@ export default function Home(): JSX.Element { const { viewerData } = useGetViewerQuery() const readerSettings = useReaderSettings() - const { articleData, articleFetchError } = useGetArticleQuery({ + const { articleData, articleFetchError } = useGetArticleQuery({ username: router.query.username as string, slug: router.query.slug as string, includeFriendsHighlights: false, @@ -62,11 +67,12 @@ export default function Home(): JSX.Element { useKeyboardShortcuts(navigationCommands(router)) - const actionHandler = useCallback(async(action: string, arg?: unknown) => { - console.log('handling action: ', action, article) + const actionHandler = useCallback( + async (action: string, arg?: unknown) => { + console.log('handling action: ', action, article) - switch (action) { - case 'unarchive': + switch (action) { + case 'unarchive': if (article) { removeItemFromCache(cache, mutate, article.id) @@ -88,45 +94,49 @@ export default function Home(): JSX.Element { router.push(`/home`) } break - case 'archive': - if (article) { - removeItemFromCache(cache, mutate, article.id) + case 'archive': + if (article) { + removeItemFromCache(cache, mutate, article.id) - await setLinkArchivedMutation({ - linkId: article.id, - archived: true, - }).then((res) => { - if (res) { - showSuccessToast('Link archived', { position: 'bottom-right' }) - } else { - // todo: revalidate or put back in cache? - showErrorToast('Error archiving link', { position: 'bottom-right' }) - } - }) + await setLinkArchivedMutation({ + linkId: article.id, + archived: true, + }).then((res) => { + if (res) { + showSuccessToast('Link archived', { position: 'bottom-right' }) + } else { + // todo: revalidate or put back in cache? + showErrorToast('Error archiving link', { + position: 'bottom-right', + }) + } + }) - router.push(`/home`) - } - break - case 'delete': - readerSettings.setShowDeleteConfirmation(true) - break - case 'openOriginalArticle': - const url = article?.url - if (url) { - window.open(url, '_blank') - } - break - case 'refreshLabels': - setLabels(arg as Label[]) - break - case 'showHighlights': - setShowHighlightsModal(true) - break - default: - readerSettings.actionHandler(action, arg) - break - } - }, [article, cache, mutate, router, readerSettings]) + router.push(`/home`) + } + break + case 'delete': + readerSettings.setShowDeleteConfirmation(true) + break + case 'openOriginalArticle': + const url = article?.url + if (url) { + window.open(url, '_blank') + } + break + case 'refreshLabels': + setLabels(arg as Label[]) + break + case 'showHighlights': + setShowHighlightsModal(true) + break + default: + readerSettings.actionHandler(action, arg) + break + } + }, + [article, cache, mutate, router, readerSettings] + ) useEffect(() => { const archive = () => { @@ -161,16 +171,15 @@ export default function Home(): JSX.Element { link: article.id, slug: article.slug, url: article.originalArticleUrl, - userId: viewerData.me.id + userId: viewerData.me.id, }) } }, [article, viewerData]) - + const deleteCurrentItem = useCallback(async () => { if (article) { removeItemFromCache(cache, mutate, article.id) - await deleteLinkMutation(article.id) - .then((res) => { + await deleteLinkMutation(article.id).then((res) => { if (res) { showSuccessToast('Page deleted', { position: 'bottom-right' }) } else { @@ -182,60 +191,72 @@ export default function Home(): JSX.Element { } }, [article]) - useRegisterActions([ - { - id: 'open', - section: 'Article', - name: 'Open original article', - shortcut: ['o'], - perform: () => { - document.dispatchEvent(new Event('openOriginalArticle')); - } - }, - { - id: 'back_home', - section: 'Article', - name: 'Return to library', - shortcut: ['u'], - perform: () => router.push(`/home`), - }, - { - id: 'archive', - section: 'Article', - name: 'Archive current item', - shortcut: ['e'], - perform: () => { - document.dispatchEvent(new Event('archive')); - } - }, - { - id: 'delete', - section: 'Article', - name: 'Delete current item', - shortcut: ['#'], - perform: () => { - document.dispatchEvent(new Event('delete')); - } - }, - { - id: 'highlight', - section: 'Article', - name: 'Highlight selected text', - shortcut: ['h'], - perform: () => { - document.dispatchEvent(new Event('highlight')); + useRegisterActions( + [ + { + id: 'open', + section: 'Article', + name: 'Open original article', + shortcut: ['o'], + perform: () => { + document.dispatchEvent(new Event('openOriginalArticle')) + }, }, - }, - { - id: 'note', - section: 'Article', - name: 'Highlight selected text and add a note', - shortcut: ['n'], - perform: () => { - document.dispatchEvent(new Event('annotate')); + { + id: 'back_home', + section: 'Article', + name: 'Return to library', + shortcut: ['u'], + perform: () => router.push(`/home`), }, - }, - ], []) + { + id: 'archive', + section: 'Article', + name: 'Archive current item', + shortcut: ['e'], + perform: () => { + document.dispatchEvent(new Event('archive')) + }, + }, + { + id: 'delete', + section: 'Article', + name: 'Delete current item', + shortcut: ['#'], + perform: () => { + document.dispatchEvent(new Event('delete')) + }, + }, + { + id: 'highlight', + section: 'Article', + name: 'Highlight selected text', + shortcut: ['h'], + perform: () => { + document.dispatchEvent(new Event('highlight')) + }, + }, + { + id: 'note', + section: 'Article', + name: 'Highlight selected text and add a note', + shortcut: ['n'], + perform: () => { + document.dispatchEvent(new Event('annotate')) + }, + }, + { + id: 'notebook', + section: 'Article', + name: 'Notebook', + shortcut: ['t'], + perform: () => { + setShowHighlightsModal(true) + }, + }, + ], + [] + ) if (articleFetchError && articleFetchError.indexOf('NOT_FOUND') > -1) { router.push('/404') @@ -248,7 +269,7 @@ export default function Home(): JSX.Element { headerToolbarControl={ @@ -268,22 +289,25 @@ export default function Home(): JSX.Element { /> - {article?.contentReader !== 'PDF' ? ( @@ -305,7 +329,7 @@ export default function Home(): JSX.Element { css={{ '@smDown': { background: theme.colors.grayBg.toString(), - } + }, }} > {article && viewerData?.me ? ( @@ -352,7 +376,9 @@ export default function Home(): JSX.Element { readerSettings.setShowEditDisplaySettingsModal(false)} + onOpenChange={() => + readerSettings.setShowEditDisplaySettingsModal(false) + } /> )} {readerSettings.showDeleteConfirmation && ( From e4c89c0256bd6df331bb73efe5a3177dab906978 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 2 Dec 2022 10:29:13 +0800 Subject: [PATCH 2/2] Set zIndex on modals so they display above the top toolbar on smaller screens --- packages/web/components/templates/article/HighlightsModal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web/components/templates/article/HighlightsModal.tsx b/packages/web/components/templates/article/HighlightsModal.tsx index 76370a261..8e5fa0607 100644 --- a/packages/web/components/templates/article/HighlightsModal.tsx +++ b/packages/web/components/templates/article/HighlightsModal.tsx @@ -42,7 +42,7 @@ export function HighlightsModal(props: HighlightsModalProps): JSX.Element { event.preventDefault() props.onOpenChange(false) }} - css={{ overflow: 'auto', px: '24px' }} + css={{ overflow: 'auto', px: '24px', zIndex: '10' }} > @@ -112,7 +112,7 @@ function ModalHighlightView(props: ModalHighlightViewProps): JSX.Element { return ( <> - +