From 45d4a99d17cd5ad943043f839ad8690f360849dd Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 24 Mar 2022 13:52:38 -0700 Subject: [PATCH] Fix Highlight type attributes --- .../templates/article/HighlightsLayer.tsx | 56 +------------------ .../{articleActions.tsx => articleActions.ts} | 2 +- .../networking/fragments/highlightFragment.ts | 4 ++ 3 files changed, 6 insertions(+), 56 deletions(-) rename packages/web/lib/{articleActions.tsx => articleActions.ts} (96%) diff --git a/packages/web/components/templates/article/HighlightsLayer.tsx b/packages/web/components/templates/article/HighlightsLayer.tsx index be622a01f..8d7ea7613 100644 --- a/packages/web/components/templates/article/HighlightsLayer.tsx +++ b/packages/web/components/templates/article/HighlightsLayer.tsx @@ -15,7 +15,6 @@ import { removeHighlights } from '../../../lib/highlights/deleteHighlight' import { createHighlight } from '../../../lib/highlights/createHighlight' import { HighlightNoteModal } from './HighlightNoteModal' import { ShareHighlightModal } from './ShareHighlightModal' -import { HighlightPostToFeedModal } from './HighlightPostToFeedModal' import { HighlightsModal } from './HighlightsModal' import { useCanShareNative } from '../../../lib/hooks/useCanShareNative' import toast from 'react-hot-toast' @@ -35,7 +34,7 @@ type HighlightsLayerProps = { articleMutations: ArticleMutations } -type HighlightModalAction = 'none' | 'addComment' | 'postToFeed' | 'share' +type HighlightModalAction = 'none' | 'addComment' | 'share' type HighlightActionProps = { highlight?: Highlight @@ -113,32 +112,6 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { [highlights, highlightLocations] ) - const postToFeedCallback = useCallback( - async (highlight: Highlight, annotation: string | undefined) => { - await shareHighlightToFeedMutation({ - id: highlight.id, - share: highlight.sharedAt == undefined, - }) - - await shareHighlightCommentMutation({ - highlightId: highlight.id, - annotation, - }) - - // Toggle the sharedAt field after mutating the highlight - const mutatedHighlight = highlight - mutatedHighlight.sharedAt = highlight.sharedAt - ? undefined - : new Date().toISOString() - mutatedHighlight.annotation = annotation - const unmutatedHighlights = highlights.filter( - ($0) => $0.id !== highlight.id - ) - setHighlights([...unmutatedHighlights, mutatedHighlight]) - }, - [highlights] - ) - const handleNativeShare = useCallback( (highlightID: string) => { navigator @@ -348,16 +321,6 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { createHighlightCallback('share') } break - case 'post': - if (focusedHighlight) { - setHighlightModalAction({ - highlight: focusedHighlight, - highlightModalAction: 'postToFeed', - }) - } else { - createHighlightCallback('postToFeed') - } - break case 'unshare': console.log('unshare') break // TODO: implement -- need to show confirmation dialog @@ -460,23 +423,6 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { ) } - if ( - highlightModalAction?.highlightModalAction == 'postToFeed' && - highlightModalAction.highlight - ) { - return ( - - setHighlightModalAction({ highlightModalAction: 'none' }) - } - /> - ) - } - if ( highlightModalAction?.highlightModalAction == 'share' && highlightModalAction.highlight diff --git a/packages/web/lib/articleActions.tsx b/packages/web/lib/articleActions.ts similarity index 96% rename from packages/web/lib/articleActions.tsx rename to packages/web/lib/articleActions.ts index fcbb235aa..f599d1bfc 100644 --- a/packages/web/lib/articleActions.tsx +++ b/packages/web/lib/articleActions.ts @@ -8,7 +8,7 @@ import { UpdateHighlightInput } from "./networking/mutations/updateHighlightMuta export type ArticleMutations = { createHighlightMutation: (input: CreateHighlightInput) => Promise deleteHighlightMutation: (highlightId: string) => Promise - mergeHighlightMutation: (input: MergeHighlightInput) => Promise + mergeHighlightMutation: (input: MergeHighlightInput) => Promise updateHighlightMutation: (input: UpdateHighlightInput) => Promise articleReadingProgressMutation: (input: ArticleReadingProgressMutationInput) => Promise } diff --git a/packages/web/lib/networking/fragments/highlightFragment.ts b/packages/web/lib/networking/fragments/highlightFragment.ts index 2e8567bf5..37a585c7a 100644 --- a/packages/web/lib/networking/fragments/highlightFragment.ts +++ b/packages/web/lib/networking/fragments/highlightFragment.ts @@ -10,6 +10,8 @@ export const highlightFragment = gql` patch annotation createdByMe + updatedAt + sharedAt } ` @@ -22,6 +24,8 @@ export type Highlight = { patch: string annotation?: string createdByMe: boolean + updatedAt: string + sharedAt: string } export type User = {