Skip to content

Commit b102bd7

Browse files
committed
fix(reader): lift annotations processed state
1 parent 31e433c commit b102bd7

File tree

9 files changed

+51
-28
lines changed

9 files changed

+51
-28
lines changed

clients/web/src/components/annotations/annotations.list.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ export class QuoteList extends Component {
5757
const { annotations, onClickEvent, shareItem, deleteAnnotation, handleImpression } = this.props
5858
const cards = []
5959

60-
annotations
60+
const annotationsWithPositon = annotations.map((annotation) => {
61+
const id = annotation.id
62+
const nodeList = document.querySelectorAll(`[data-annotation-id="${id}"]`)
63+
const node = nodeList[0]
64+
if (!node) return annotation
65+
return { ...annotation, position: node.offsetTop }
66+
})
67+
68+
annotationsWithPositon
6169
.sort((a, b) => a.position - b.position)
6270
.forEach((annot) => {
6371
// const active = annot.coordY > viewPort.top && annot.coordY < viewPort.bottom

clients/web/src/components/annotations/annotations.menu.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const relativeWrapper = css`
4444
color: var(--color-textPrimary);
4545
background-color: var(--color-actionPrimarySubdued);
4646
}
47-
.icon {
47+
& > .icon {
4848
margin-right: 0;
4949
transform: translateY(0);
5050
}

clients/web/src/components/annotations/annotations.tics.js

+2-16
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,12 @@ const flyAwayWrapper = css`
6969
`
7070

7171
const menuWrapper = css`
72-
min-width: 200px;
7372
list-style-type: none;
7473
padding-left: 0;
75-
transform: translate(-24px, -20px);
7674
position: absolute;
77-
bottom: 0;
78-
right: -32px;
75+
bottom: 18px;
76+
right: 24px;
7977
z-index: var(--zIndexModal);
80-
81-
button {
82-
box-shadow: none;
83-
}
84-
button .icon {
85-
margin-top: -5px;
86-
}
87-
88-
& > div {
89-
right: 0;
90-
text-align: right;
91-
}
9278
`
9379

9480
const floatingCardStyles = css`

clients/web/src/components/annotations/utilities.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function highlightAnnotation(annotation, onHover, element, callback) {
88
}
99

1010
// Main highlight function accepting an array of annotations
11-
export function highlightAnnotations({ node, annotations }) {
11+
export function highlightAnnotations({ node, annotations, annotationsCallback }) {
1212
const tapListener = () => {}
1313
const callback = () => {}
1414

@@ -60,6 +60,8 @@ export function highlightAnnotations({ node, annotations }) {
6060
doc,
6161
callback
6262
})
63+
64+
if (annotationsCallback) annotationsCallback()
6365
}
6466

6567
// Helper Functions

clients/web/src/components/reader/content.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const Content = ({
1717
content,
1818
images,
1919
videos,
20+
annotationsCallback,
2021
annotations = [],
2122
onHighlightHover,
2223
externalLinkClick = () => {},
@@ -44,8 +45,7 @@ export const Content = ({
4445

4546
const processAnnotations = async (annotations) => {
4647
removeAllHighlights()
47-
48-
highlightAnnotations({ annotations, node: articleRef.current })
48+
highlightAnnotations({ annotations, node: articleRef.current, annotationsCallback })
4949
}
5050

5151
if (content) externalizeLinks()
@@ -60,7 +60,16 @@ export const Content = ({
6060
link.removeEventListener('click', sendExternalLinkClick)
6161
})
6262
}
63-
}, [annotations, content, externalLinkClick, highlightHover, images, videos])
63+
}, [
64+
annotations,
65+
content,
66+
externalLinkClick,
67+
highlightHover,
68+
annotationsCallback,
69+
images,
70+
videos,
71+
articleRef
72+
])
6473

6574
return (
6675
<article

clients/web/src/components/reader/sidebar.js

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const Sidebar = ({
7373
highlights,
7474
articleRef,
7575
shareItem,
76+
annotationsProcessed,
7677
deleteAnnotation,
7778
isPremium,
7879
handleImpression
@@ -120,6 +121,7 @@ export const Sidebar = ({
120121
visible={!sideBarOpen}
121122
shareItem={shareItem}
122123
annotations={highlights}
124+
annotationsProcessed={annotationsProcessed}
123125
annotationCount={highlights.length}
124126
deleteAnnotation={deleteAnnotation}
125127
onClickEvent={handleAnnotationClick}

clients/web/src/connectors/reader/content.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Content } from 'components/reader/content'
33
import { Highlights } from './highlights'
44
import { sendSnowplowEvent } from 'connectors/snowplow/snowplow.state'
55

6-
export const ContentWrapper = ({ id, articleRef }) => {
6+
export const ContentWrapper = ({ id, articleRef, annotationsProcessed, annotationsCallback }) => {
77
const dispatch = useDispatch()
88

99
const item = useSelector((state) => state.itemsDisplay[id])
@@ -19,13 +19,14 @@ export const ContentWrapper = ({ id, articleRef }) => {
1919

2020
return (
2121
<>
22-
<Highlights id={id} articleRef={articleRef} />
22+
<Highlights id={id} articleRef={articleRef} annotationsProcessed={annotationsProcessed} />
2323
<Content
2424
articleRef={articleRef}
2525
annotations={highlights}
2626
images={images}
2727
videos={videos}
2828
content={article}
29+
annotationsCallback={annotationsCallback}
2930
externalLinkClick={externalLinkClick}
3031
style={{ padding: '40px' }}
3132
/>

clients/web/src/connectors/reader/sidebar.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { mutationHighlightDelete } from 'connectors/items/mutation-highlight.sta
66
import { shareAction } from 'connectors/items/mutation-share.state'
77
import { sendSnowplowEvent } from 'connectors/snowplow/snowplow.state'
88

9-
export const SidebarWrapper = ({ id, articleRef }) => {
9+
export const SidebarWrapper = ({ id, articleRef, annotationsProcessed }) => {
1010
const dispatch = useDispatch()
1111

1212
const item = useSelector((state) => state.itemsDisplay[id])
@@ -41,6 +41,7 @@ export const SidebarWrapper = ({ id, articleRef }) => {
4141
isPremium={isPremium}
4242
sideBarOpen={sideBarOpen}
4343
toggleSidebar={handleSidebarToggle}
44+
annotationsProcessed={annotationsProcessed}
4445
highlights={highlights}
4546
deleteAnnotation={removeAnnotation}
4647
shareItem={itemShare}

clients/web/src/containers/read/reader.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Head from 'next/head'
22
import { useRouter } from 'next/router'
3-
import { useEffect, useRef } from 'react'
3+
import { useEffect, useRef, useState, useCallback } from 'react'
44
import { useDispatch, useSelector } from 'react-redux'
55
import { css, cx } from '@emotion/css'
66

@@ -83,6 +83,12 @@ export default function Reader() {
8383

8484
const articleRef = useRef(null)
8585

86+
const [annotationsProcessed, setAnnotationsProcessed] = useState(false)
87+
const annotationsCallback = useCallback(() => {
88+
if (annotationsProcessed) return
89+
setAnnotationsProcessed(true)
90+
}, [annotationsProcessed])
91+
8692
// Item Data
8793
const itemId = useSelector((state) => state.idMap[slug])
8894
const item = useSelector((state) => state.itemsDisplay[itemId])
@@ -203,10 +209,18 @@ export default function Reader() {
203209
<Toolbar id={itemId} />
204210

205211
<main className={articleWrapperStyles}>
206-
<SidebarWrapper id={itemId} articleRef={articleRef} />
212+
<SidebarWrapper
213+
id={itemId}
214+
articleRef={articleRef}
215+
annotationsProcessed={annotationsProcessed}
216+
/>
207217
<article className={articleClasses} style={customStyles}>
208218
<Header id={itemId} />
209-
<ContentWrapper id={itemId} articleRef={articleRef} />
219+
<ContentWrapper
220+
id={itemId}
221+
articleRef={articleRef}
222+
annotationsCallback={annotationsCallback}
223+
/>
210224
</article>
211225
</main>
212226

0 commit comments

Comments
 (0)