Skip to content

Commit

Permalink
[newswires] only load if it's a newswires domain (or local pinboard s…
Browse files Browse the repository at this point in the history
…andbox)
  • Loading branch information
twrichards committed Dec 17, 2024
1 parent 06d3d07 commit 8764cfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
7 changes: 5 additions & 2 deletions client/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -510,7 +513,7 @@ export const PinBoardApp = ({
expand={() => setIsExpanded(true)}
/>
))}
<NewswiresIntegration />
{isNewswiresDomain && <NewswiresIntegration />}
</TourStateProvider>
</GlobalStateProvider>
</ApolloProvider>
Expand Down
18 changes: 7 additions & 11 deletions client/src/newswires/newswiresIntegration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 8764cfb

Please sign in to comment.