From 8764cfb5561de8fded1fd6d0905c1262ced5d9c2 Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Tue, 17 Dec 2024 09:44:17 +0000 Subject: [PATCH] [newswires] only load if it's a newswires domain (or local pinboard sandbox) --- client/src/app.tsx | 7 +++++-- client/src/newswires/newswiresIntegration.tsx | 18 +++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/client/src/app.tsx b/client/src/app.tsx index d74ad398..beb82501 100644 --- a/client/src/app.tsx +++ b/client/src/app.tsx @@ -58,7 +58,10 @@ import { SUGGEST_ALTERNATE_CROP_QUERY_SELECTOR, SuggestAlternateCrops, } from "./fronts/suggestAlternateCrops"; -import { NewswiresIntegration } from "./newswires/newswiresIntegration"; +import { + isNewswiresDomain, + NewswiresIntegration, +} from "./newswires/newswiresIntegration"; const PRESELECT_PINBOARD_HTML_TAG = "pinboard-preselect"; const PRESET_UNREAD_NOTIFICATIONS_COUNT_HTML_TAG = "pinboard-bubble-preset"; @@ -510,7 +513,7 @@ export const PinBoardApp = ({ expand={() => setIsExpanded(true)} /> ))} - + {isNewswiresDomain && } diff --git a/client/src/newswires/newswiresIntegration.tsx b/client/src/newswires/newswiresIntegration.tsx index 83045af9..1d19c6ca 100644 --- a/client/src/newswires/newswiresIntegration.tsx +++ b/client/src/newswires/newswiresIntegration.tsx @@ -19,6 +19,13 @@ interface ButtonPosition { unRoundedCorner: "bottom-left" | "top-right" | "top-left" | "bottom-right"; } +export const isNewswiresDomain = [ + "https://pinboard.local.dev-gutools.co.uk", // local testing in Pinboard's local sandbox + "https://newswires.local.dev-gutools.co.uk", + "https://newswires.code.dev-gutools.co.uk", + "https://newswires.gutools.co.uk", +].includes(window.location.hostname); + export const NewswiresIntegration = () => { const { setPayloadToBeSent, setIsExpanded } = useGlobalStateContext(); @@ -113,17 +120,6 @@ export const NewswiresIntegration = () => { useEffect(() => { document.addEventListener("selectionchange", debouncedSelectionHandler); - /** - * todos: - * [ ] limit to newswires domain - * [x] add selection listener -- addEventListener("selectionchange", (event) => {}); - * [x] debounce handler - * [x] check parent node of selection is newswires body text el (maybe add data attribute to body text el) - * - (find first shared parent of anchorNode and focusNode, make sure we're not sharing bits of text outside of the target) - * [x] extract HTML from selection (see chat thread) - * [x] render button when there's a selection - * [x] do things with pinboard - */ return () => document.removeEventListener( "selectionchange",