Merge pull request #2673 from omnivore-app/feature/highlight-color-in-api

add color to create/update/merge highlight api and highlight schema
This commit is contained in:
Jackson Harper
2023-08-23 10:20:23 +08:00
committed by GitHub
6 changed files with 29 additions and 0 deletions

View File

@ -107,6 +107,7 @@ export interface Highlight {
highlightPositionAnchorIndex?: number | null
type: HighlightType
html?: string | null
color?: string | null
}
export interface RecommendingUser {

View File

@ -351,6 +351,7 @@ export enum CreateHighlightErrorCode {
export type CreateHighlightInput = {
annotation?: InputMaybe<Scalars['String']>;
articleId: Scalars['ID'];
color?: InputMaybe<Scalars['String']>;
highlightPositionAnchorIndex?: InputMaybe<Scalars['Int']>;
highlightPositionPercent?: InputMaybe<Scalars['Float']>;
html?: InputMaybe<Scalars['String']>;
@ -908,6 +909,7 @@ export type GroupsSuccess = {
export type Highlight = {
__typename?: 'Highlight';
annotation?: Maybe<Scalars['String']>;
color?: Maybe<Scalars['String']>;
createdAt: Scalars['Date'];
createdByMe: Scalars['Boolean'];
highlightPositionAnchorIndex?: Maybe<Scalars['Int']>;
@ -1160,6 +1162,7 @@ export enum MergeHighlightErrorCode {
export type MergeHighlightInput = {
annotation?: InputMaybe<Scalars['String']>;
articleId: Scalars['ID'];
color?: InputMaybe<Scalars['String']>;
highlightPositionAnchorIndex?: InputMaybe<Scalars['Int']>;
highlightPositionPercent?: InputMaybe<Scalars['Float']>;
html?: InputMaybe<Scalars['String']>;
@ -2308,6 +2311,7 @@ export type SearchItem = {
annotation?: Maybe<Scalars['String']>;
archivedAt?: Maybe<Scalars['Date']>;
author?: Maybe<Scalars['String']>;
color?: Maybe<Scalars['String']>;
content?: Maybe<Scalars['String']>;
contentReader: ContentReader;
createdAt: Scalars['Date'];
@ -2847,6 +2851,7 @@ export enum UpdateHighlightErrorCode {
export type UpdateHighlightInput = {
annotation?: InputMaybe<Scalars['String']>;
color?: InputMaybe<Scalars['String']>;
highlightId: Scalars['ID'];
html?: InputMaybe<Scalars['String']>;
quote?: InputMaybe<Scalars['String']>;
@ -4897,6 +4902,7 @@ export type GroupsSuccessResolvers<ContextType = ResolverContext, ParentType ext
export type HighlightResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['Highlight'] = ResolversParentTypes['Highlight']> = {
annotation?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
color?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
createdByMe?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
highlightPositionAnchorIndex?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;
@ -5565,6 +5571,7 @@ export type SearchItemResolvers<ContextType = ResolverContext, ParentType extend
annotation?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
archivedAt?: Resolver<Maybe<ResolversTypes['Date']>, ParentType, ContextType>;
author?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
color?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
content?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
contentReader?: Resolver<ResolversTypes['ContentReader'], ParentType, ContextType>;
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;

View File

@ -303,6 +303,7 @@ enum CreateHighlightErrorCode {
input CreateHighlightInput {
annotation: String
articleId: ID!
color: String
highlightPositionAnchorIndex: Int
highlightPositionPercent: Float
html: String
@ -805,6 +806,7 @@ type GroupsSuccess {
type Highlight {
annotation: String
color: String
createdAt: Date!
createdByMe: Boolean!
highlightPositionAnchorIndex: Int
@ -1034,6 +1036,7 @@ enum MergeHighlightErrorCode {
input MergeHighlightInput {
annotation: String
articleId: ID!
color: String
highlightPositionAnchorIndex: Int
highlightPositionPercent: Float
html: String
@ -1685,6 +1688,7 @@ type SearchItem {
annotation: String
archivedAt: Date
author: String
color: String
content: String
contentReader: ContentReader!
createdAt: Date!
@ -2183,6 +2187,7 @@ enum UpdateHighlightErrorCode {
input UpdateHighlightInput {
annotation: String
color: String
highlightId: ID!
html: String
quote: String

View File

@ -148,6 +148,7 @@ export const mergeHighlightResolver = authorized<
/* Compute merged annotation form the order of highlights appearing on page */
const mergedAnnotations: string[] = []
const mergedLabels: Label[] = []
const mergedColors: string[] = []
const pageHighlights = page.highlights.filter((highlight) => {
// filter out highlights that are in the overlap list
// and are of type highlight (not annotation or note)
@ -168,10 +169,15 @@ export const mergeHighlightResolver = authorized<
}
})
}
// collect colors of overlap highlights
highlight.color && mergedColors.push(highlight.color)
return false
}
return true
})
// use new color or the color of the last overlap highlight
const color = newHighlightInput.color || mergedColors[mergedColors.length - 1]
try {
const highlight: HighlightData = {
...newHighlightInput,
@ -182,6 +188,7 @@ export const mergeHighlightResolver = authorized<
mergedAnnotations.length > 0 ? mergedAnnotations.join('\n') : null,
type: HighlightType.Highlight,
labels: mergedLabels,
color,
}
const merged = await updatePage(
@ -253,6 +260,7 @@ export const updateHighlightResolver = authorized<
annotation,
quote,
updatedAt: new Date(),
color: input.color,
}
log.info('Updating a highlight', {

View File

@ -711,6 +711,7 @@ const schema = gql`
labels: [Label!]
type: HighlightType!
html: String
color: String
}
input CreateHighlightInput {
@ -727,6 +728,7 @@ const schema = gql`
highlightPositionAnchorIndex: Int
type: HighlightType
html: String
color: String
}
type CreateHighlightSuccess {
@ -760,6 +762,7 @@ const schema = gql`
highlightPositionPercent: Float
highlightPositionAnchorIndex: Int
html: String
color: String
}
type MergeHighlightSuccess {
@ -787,6 +790,7 @@ const schema = gql`
sharedAt: Date
quote: String @sanitize(maxLength: 12000, minLength: 1)
html: String
color: String
}
type UpdateHighlightSuccess {
@ -1584,6 +1588,7 @@ const schema = gql`
shortId: String
quote: String
annotation: String
color: String
labels: [Label!]
subscription: String
unsubMailTo: String

View File

@ -131,6 +131,9 @@
"html": {
"type": "text",
"analyzer": "strip_html_analyzer"
},
"color": {
"type": "keyword"
}
}
},