@@ -19,6 +19,16 @@ export interface SearchResponse {
19
19
}
20
20
}
21
21
22
+ export enum PageType {
23
+ Article = 'ARTICLE' ,
24
+ Book = 'BOOK' ,
25
+ File = 'FILE' ,
26
+ Profile = 'PROFILE' ,
27
+ Unknown = 'UNKNOWN' ,
28
+ Website = 'WEBSITE' ,
29
+ Highlights = 'HIGHLIGHTS' ,
30
+ }
31
+
22
32
export interface Article {
23
33
title : string
24
34
siteName : string
@@ -30,6 +40,7 @@ export interface Article {
30
40
highlights ?: Highlight [ ]
31
41
updatedAt : string
32
42
savedAt : string
43
+ pageType : PageType
33
44
}
34
45
35
46
export interface Label {
@@ -43,6 +54,11 @@ export interface Highlight {
43
54
patch : string
44
55
}
45
56
57
+ export interface HighlightPoint {
58
+ left : number
59
+ top : number
60
+ }
61
+
46
62
const endpoint = 'https://api-prod.omnivore.app/api/graphql'
47
63
48
64
export const loadArticle = async (
@@ -74,7 +90,7 @@ export const loadArticles = async (
74
90
'content-type' : 'application/json' ,
75
91
authorization : apiKey ,
76
92
} ,
77
- body : `{"query":"\\n query Search($after: String, $first: Int, $query: String) {\\n search(first: $first, after: $after, query: $query) {\\n ... on SearchSuccess {\\n edges {\\n node {\\n title\\n slug\\n siteName\\n originalArticleUrl\\n url\\n author\\n updatedAt\\n description\\n savedAt\\n highlights {\\n id\\n quote\\n annotation\\n patch\\n }\\n labels {\\n name\\n }\\n }\\n }\\n pageInfo {\\n hasNextPage\\n }\\n }\\n ... on SearchError {\\n errorCodes\\n }\\n }\\n }\\n ","variables":{"after":"${ after } ","first":${ first } , "query":"${
93
+ body : `{"query":"\\n query Search($after: String, $first: Int, $query: String) {\\n search(first: $first, after: $after, query: $query) {\\n ... on SearchSuccess {\\n edges {\\n node {\\n title\\n slug\\n siteName\\n originalArticleUrl\\n url\\n author\\n updatedAt\\n description\\n savedAt\\n pageType\\n highlights {\\n id\\n quote\\n annotation\\n patch\\n }\\n labels {\\n name\\n }\\n }\\n }\\n pageInfo {\\n hasNextPage\\n }\\n }\\n ... on SearchError {\\n errorCodes\\n }\\n }\\n }\\n ","variables":{"after":"${ after } ","first":${ first } , "query":"${
78
94
updatedAt ? 'updated:' + updatedAt : ''
79
95
} sort:saved-asc ${ query } "}}`,
80
96
method : 'POST' ,
@@ -91,3 +107,23 @@ export const getHighlightLocation = (patch: string): number => {
91
107
const patches = dmp . patch_fromText ( patch )
92
108
return patches [ 0 ] . start1 || 0
93
109
}
110
+
111
+ export const getHighlightPoint = ( patch : string ) : HighlightPoint => {
112
+ const { bbox } = JSON . parse ( patch ) as { bbox : number [ ] }
113
+ if ( ! bbox || bbox . length !== 4 ) {
114
+ return { left : 0 , top : 0 }
115
+ }
116
+ return { left : bbox [ 0 ] , top : bbox [ 1 ] }
117
+ }
118
+
119
+ export const compareHighlightsInFile = ( a : Highlight , b : Highlight ) : number => {
120
+ // get the position of the highlight in the file
121
+ const highlightPointA = getHighlightPoint ( a . patch )
122
+ const highlightPointB = getHighlightPoint ( b . patch )
123
+ if ( highlightPointA . top === highlightPointB . top ) {
124
+ // if top is same, sort by left
125
+ return highlightPointA . left - highlightPointB . left
126
+ }
127
+ // sort by top
128
+ return highlightPointA . top - highlightPointB . top
129
+ }
0 commit comments