-
Notifications
You must be signed in to change notification settings - Fork 342
/
result-item.tsx
189 lines (173 loc) · 6.8 KB
/
result-item.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import React, {
PureComponent,
ReactNode,
MouseEventHandler,
DragEventHandler,
} from 'react'
import cx from 'classnames'
import { runInBackground } from 'src/util/webextensionRPC'
import { AnnotationInterface } from 'src/annotations/background/types'
import AnnotationList from './annotation-list'
import LoadingIndicator from '@worldbrain/memex-common/lib/common-ui/components/loading-indicator'
import { SocialPage } from 'src/social-integration/types'
import PageResultItem from './page-result-item'
import SocialResultItem from './social-result-item'
import SemiCircularRibbon from './semi-circular-ribbon'
import { RemoteCopyPasterInterface } from 'src/copy-paster/background/types'
import { ContentSharingInterface } from 'src/content-sharing/background/types'
const styles = require('./result-item.css')
// TODO (sidebar-refactor): I'm simply setting this up and passing this down
// to the baby comps to save time, but all these components need to be sorted sometime
const annotationsBG = runInBackground<AnnotationInterface<'caller'>>()
export interface Props extends Partial<SocialPage> {
url: string
fullUrl: string
title?: string
favIcon?: string
nullImg?: string
screenshot?: string
displayTime?: string
isDeleting: boolean
tags: string[]
lists: string[]
hasBookmark?: boolean
isSidebarOpen?: boolean
arePickersOpen?: boolean
isListFilterActive: boolean
areScreenshotsEnabled?: boolean
areAnnotationsExpanded?: boolean
isResponsibleForSidebar?: boolean
activeShareMenuNoteId: string | undefined
activeTagPickerNoteId: string | undefined
activeListPickerNoteId: string | undefined
activeCopyPasterAnnotationId: string | undefined
isOverview?: boolean
isSocial?: boolean
annotations?: any[]
annotsCount?: number
tagHolder: ReactNode
tagManager: ReactNode
listManager: ReactNode
copyPasterManager: ReactNode
onTagBtnClick: MouseEventHandler
onListBtnClick: MouseEventHandler
onTrashBtnClick: MouseEventHandler
onReaderBtnClick?: MouseEventHandler
onCommentBtnClick: MouseEventHandler
onToggleBookmarkClick: MouseEventHandler
onCopyPasterBtnClick: MouseEventHandler
handleCrossRibbonClick: MouseEventHandler
goToAnnotation: (annotation: any) => void
resetUrlDragged: () => void
setUrlDragged: (url: string) => void
setTagButtonRef: (el: HTMLElement) => void
setListButtonRef: (el: HTMLElement) => void
setCopyPasterButtonRef: (el: HTMLElement) => void
setActiveTagPickerNoteId: (id: string) => void
setActiveListPickerNoteId: (id: string) => void
setActiveShareMenuNoteId?: (id: string) => void
setActiveCopyPasterAnnotationId?: (id: string) => void
contentSharing: ContentSharingInterface
copyPaster: RemoteCopyPasterInterface
}
class ResultItem extends PureComponent<Props> {
get hrefToPage() {
return `${this.props.fullUrl}`
}
dragStart: DragEventHandler<HTMLAnchorElement> = (e) => {
const { fullUrl, setUrlDragged, isSocial } = this.props
setUrlDragged(fullUrl)
const crt = this.props.isOverview
? document.getElementById('dragged-element')
: (document
.querySelector('.memex-ribbon-sidebar-container')
.shadowRoot.querySelector('#dragged-element') as HTMLElement)
crt.style.display = 'block'
const data = JSON.stringify({
url: fullUrl,
isSocialPost: isSocial,
})
e.dataTransfer.setData('text/plain', data)
e.dataTransfer.setDragImage(crt, 10, 10)
}
private handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
if (this.props.arePickersOpen || this.props.isSidebarOpen) {
e.preventDefault()
}
}
private renderAnnotsList() {
if (!(this.props.annotations && this.props.annotations.length)) {
return null
}
return (
<AnnotationList
{...this.props}
isExpandedOverride={this.props.areAnnotationsExpanded}
openAnnotationSidebar={this.props.onCommentBtnClick}
pageUrl={this.hrefToPage}
annotations={this.props.annotations}
goToAnnotation={this.props.goToAnnotation}
handleDeleteAnnotation={(url) =>
annotationsBG.deleteAnnotation(url)
}
// handleEditAnnotation={async (url, comment, tags) => {
// await annotationsBG.editAnnotation(url, comment)
// await annotationsBG.updateAnnotationTags({ url, tags })
// }}
/>
)
}
render() {
return (
<li
className={cx(styles.listItem, styles.resultBox, {
[styles.isDeleting]: this.props.isDeleting,
})}
>
<div className={styles.resultBoxItem}>
{this.props.isDeleting && <LoadingIndicator />}
{this.props.tagManager}
{this.props.listManager}
{this.props.copyPasterManager}
<div
className={cx(
styles.rootContainer,
styles.rootContainerOverview,
{
[styles.tweetRootContainer]: this.props
.isSocial,
[styles.isSidebarOpen]: this.props
.isResponsibleForSidebar,
},
)}
>
<a
onClick={this.handleClick}
onDragStart={this.dragStart}
onDragEnd={this.props.resetUrlDragged}
className={cx(styles.root, styles.rootOverview)}
draggable
href={this.hrefToPage}
target="_blank"
>
{this.props.isSocial ? (
<SocialResultItem {...this.props} />
) : (
<PageResultItem {...this.props} />
)}
</a>
</div>
{this.renderAnnotsList()}
</div>
{this.props.isListFilterActive && (
<div className={styles.removeCollectionItemBox}>
<SemiCircularRibbon
onClick={this.props.handleCrossRibbonClick}
/>
</div>
)}
</li>
)
}
}
export default ResultItem