Skip to content

Commit

Permalink
fix - zoom to target when search result is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
wykhuh committed May 1, 2024
1 parent 344df42 commit 0c56986
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/components/Viewer/InformationPanel/ContentSearch/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect } from "react";
import { Item as ItemStyled } from "./Item.styled";

import {
Expand All @@ -18,9 +18,17 @@ import AnnotationItemPlainText from "./PlainText";

type Props = {
annotation: AnnotationNormalized;
activeContentSearchTarget?: string;
setActiveContentSearchTarget: React.Dispatch<
React.SetStateAction<string | undefined>
>;
};

export const ContentSearchItem: React.FC<Props> = ({ annotation }) => {
export const ContentSearchItem: React.FC<Props> = ({
annotation,
activeContentSearchTarget,
setActiveContentSearchTarget,
}) => {
const dispatch: any = useViewerDispatch();
const viewerState: ViewerContextStore = useViewerState();
const {
Expand All @@ -31,7 +39,6 @@ export const ContentSearchItem: React.FC<Props> = ({ annotation }) => {
configOptions,
OSDImageLoaded,
} = viewerState;
const [activeContentSearchTarget, setActiveContentSearchTarget] = useState();

const canvas: CanvasNormalized = vault.get({
id: activeCanvas,
Expand Down
12 changes: 10 additions & 2 deletions src/components/Viewer/InformationPanel/ContentSearch/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import {
AnnotationNormalized,
AnnotationPageNormalized,
Expand All @@ -17,6 +17,9 @@ type GroupedAnnotations = {
export const ContentSearchPage: React.FC<Props> = ({ annotationPage }) => {
const viewerState: ViewerContextStore = useViewerState();
const { contentSearchVault, configOptions } = viewerState;
const [activeContentSearchTarget, setActiveContentSearchTarget] = useState<
string | undefined
>();

const searchResultsLimit = configOptions.contentSearch?.searchResultsLimit;
const searchText = configOptions.localeText?.contentSearch;
Expand Down Expand Up @@ -51,7 +54,12 @@ export const ContentSearchPage: React.FC<Props> = ({ annotationPage }) => {
: annotations;

return annotationsShown.map((annotation, i) => (
<ContentSearchItem key={i} annotation={annotation} />
<ContentSearchItem
key={i}
annotation={annotation}
activeContentSearchTarget={activeContentSearchTarget}
setActiveContentSearchTarget={setActiveContentSearchTarget}
/>
));
}

Expand Down

0 comments on commit 0c56986

Please sign in to comment.