Skip to content

Commit 79235d4

Browse files
committed
add option item id to highlight when using peekAtPinboard
1 parent 04916ba commit 79235d4

4 files changed

+31
-6
lines changed

client/src/fronts/frontsPinboardArticleButton.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ export const FrontsPinboardArticleButton = ({
146146
event.dataTransfer.setData("URL", payload.embeddableUrl);
147147
}}
148148
onClick={() => {
149-
peekAtPinboard(item.pinboardId);
150-
console.log(item.id); //TODO scroll to selected item to see context
149+
peekAtPinboard(item.pinboardId, item.id);
151150
}}
152151
></img>
153152
))}

client/src/fronts/suggestAlternateCrops.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ export const SuggestAlternateCrops = ({
225225
`}
226226
src={payload.thumbnail}
227227
onClick={() => {
228-
peekAtPinboard(item.pinboardId);
229-
console.log(item.id); //TODO scroll to selected item to see context
228+
peekAtPinboard(item.pinboardId, item.id);
230229
}}
231230
></img>
232231
))}

client/src/globalState.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ interface GlobalStateContextShape {
6464
openPinboard: (
6565
isDemo: boolean
6666
) => (pinboardData: PinboardData, isOpenInNewTab: boolean) => void;
67-
peekAtPinboard: (pinboardId: string) => void;
67+
peekAtPinboard: (pinboardId: string, maybeItemIdToHighlight?: string) => void;
6868
openPinboardInNewTab: (pinboardData: PinboardData) => void;
6969
closePinboard: (pinboardId: string) => void;
7070
preselectedPinboard: PreselectedPinboard;
@@ -75,6 +75,9 @@ interface GlobalStateContextShape {
7575
selectedPinboardId: string | null | undefined;
7676
clearSelectedPinboard: () => void;
7777

78+
maybeItemIdToHighlight: string | null;
79+
clearMaybeItemIdToHighlight: () => void;
80+
7881
hasEverUsedTour: boolean | undefined;
7982
visitTourStep: (tourStepId: string) => void;
8083

@@ -384,8 +387,14 @@ export const GlobalStateProvider = ({
384387
}
385388
};
386389

387-
const peekAtPinboard = (pinboardId: string) => {
390+
const [maybeItemIdToHighlight, setMaybeItemIdToHighlight] = useState<
391+
string | null
392+
>(null);
393+
const clearMaybeItemIdToHighlight = () => setMaybeItemIdToHighlight(null);
394+
395+
const peekAtPinboard = (pinboardId: string, itemIdToHighlight?: string) => {
388396
setSelectedPinboardId(pinboardId);
397+
itemIdToHighlight && setMaybeItemIdToHighlight(itemIdToHighlight);
389398
setIsExpanded(true);
390399
};
391400

@@ -582,6 +591,9 @@ export const GlobalStateProvider = ({
582591
selectedPinboardId,
583592
clearSelectedPinboard,
584593

594+
maybeItemIdToHighlight,
595+
clearMaybeItemIdToHighlight,
596+
585597
hasEverUsedTour,
586598
visitTourStep,
587599

client/src/scrollableItems.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { PendingItem } from "./types/PendingItem";
2727
import { UserLookup } from "./types/UserLookup";
2828
import { PINBOARD_ITEM_ID_QUERY_PARAM } from "../../shared/constants";
2929
import { useTourProgress } from "./tour/tourState";
30+
import { useGlobalStateContext } from "./globalState";
3031

3132
interface ScrollableItemsProps {
3233
items: Array<PendingItem | Item>;
@@ -261,6 +262,20 @@ export const ScrollableItems = ({
261262
window.removeEventListener("message", handleItemFromServiceWorker);
262263
}, []);
263264

265+
const { maybeItemIdToHighlight, clearMaybeItemIdToHighlight } =
266+
useGlobalStateContext();
267+
useEffect(() => {
268+
if (
269+
maybeItemIdToHighlight &&
270+
items.some((_) => _.id === maybeItemIdToHighlight)
271+
) {
272+
setTimeout(() => {
273+
scrollToItem(maybeItemIdToHighlight);
274+
clearMaybeItemIdToHighlight();
275+
}, 250);
276+
}
277+
}, [items, maybeItemIdToHighlight]);
278+
264279
return (
265280
<div
266281
ref={setScrollableAreaRef}

0 commit comments

Comments
 (0)