Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multiple bugs on mobile #273

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/src/main/javascript/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ export default function Header({
flexShrink: 0,
alignItems: "center",
visibility: searchSectionHidden ? "hidden" : "unset",
pointerEvents: searchSectionHidden ? 'none' : 'unset'
}}
>
<SearchBySelect />
<SearchBar oncoTreeData={oncoTreeData} oncoTree={oncoTree} disabled={searchSectionHidden} />
<SearchBar oncoTreeData={oncoTreeData} oncoTree={oncoTree} />
<div style={{ marginRight: 20 }} />
<VersionSelect
onVersionChange={onVersionChange}
Expand Down
70 changes: 39 additions & 31 deletions web/src/main/javascript/src/components/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface ISearchBarProps {
oncoTreeData: OncoTreeNode;
oncoTree: OncoTree | undefined;
mobileView?: boolean;
disabled?: boolean;
}

const NEXT_BUTTON_DATA_TYPE = "nextButton";
Expand All @@ -41,7 +40,6 @@ export default function SearchBar({
oncoTreeData,
oncoTree,
mobileView = false,
disabled = false,
}: ISearchBarProps) {
const [searchParams, setSearchParams] = useSearchParams();
const search = searchParams.get("search");
Expand Down Expand Up @@ -207,7 +205,6 @@ export default function SearchBar({
<ReactSelect
inputValue={input}
value={getSearchBarValue()}
isDisabled={disabled}
placeholder={
isValidField(field)
? SEARCH_BY_FIELD_INFO[field].searchBarPlaceHolder
Expand All @@ -229,7 +226,7 @@ export default function SearchBar({
}}
options={options}
components={{
ClearIndicator,
ClearIndicator: (props) => <ClearIndicator {...props} searchResults={cancerTypeResults} searchResultsIndex={cancerTypeResultsIndex} />,
Control,
}}
styles={{
Expand Down Expand Up @@ -262,26 +259,31 @@ export default function SearchBar({
</div>
);

interface IClearIndicatorProps extends ClearIndicatorProps<
OncoTreeSearchOption,
false,
GroupBase<OncoTreeSearchOption>
> {
searchResults: D3OncoTreeNode[] | undefined,
searchResultsIndex: number | undefined
}

function ClearIndicator(
props: ClearIndicatorProps<
OncoTreeSearchOption,
false,
GroupBase<OncoTreeSearchOption>
>,
{searchResults, searchResultsIndex, ...props}: IClearIndicatorProps,
) {
const inputStyle = props.getStyles("input", { ...props, isHidden: false });
const inputColor = inputStyle.color ?? "black";
const clearIndicatorClass = css(props.getStyles("clearIndicator", props));

const resultsAndIndexDefined =
cancerTypeResults !== undefined && cancerTypeResultsIndex !== undefined;
searchResults !== undefined && searchResultsIndex !== undefined;

function getResultsNumberSpan() {
if (!resultsAndIndexDefined) {
return undefined;
}

if (cancerTypeResults.length === 0) {
if (searchResults.length === 0) {
return (
<span
className={clearIndicatorClass}
Expand All @@ -300,45 +302,51 @@ export default function SearchBar({
style={{
color: Array.isArray(inputColor) ? inputColor[0] : inputColor,
}}
>{`${cancerTypeResultsIndex + 1}/${cancerTypeResults.length}`}</span>
>{`${searchResultsIndex + 1}/${searchResults.length}`}</span>
);
}

const getPreviousResult = resultsAndIndexDefined
? () => {
let newIndex = cancerTypeResults.length - 1;
const getPreviousResult = useCallback(() => {
if (!resultsAndIndexDefined) {
return;
}

let newIndex = searchResults.length - 1;
if (cancerTypeResultsIndex !== 0) {
newIndex = cancerTypeResultsIndex - 1;
newIndex = searchResultsIndex - 1;
}
oncoTree?.focus(cancerTypeResults[newIndex]);
oncoTree?.focus(searchResults[newIndex]);
setCancerTypeResultsIndex(newIndex);
}, [resultsAndIndexDefined, searchResults, searchResultsIndex]);

const getNextResult = useCallback(() => {
if (!resultsAndIndexDefined) {
return;
}
: undefined;

const getNextResult = resultsAndIndexDefined
? () => {
let newIndex = 0;
let newIndex = 0;
if (
cancerTypeResultsIndex !==
cancerTypeResults.length - 1
searchResults.length - 1
) {
newIndex = cancerTypeResultsIndex + 1;
newIndex = searchResultsIndex + 1;
}
oncoTree?.focus(cancerTypeResults[newIndex]);
oncoTree?.focus(searchResults[newIndex]);
setCancerTypeResultsIndex(newIndex);
}
: undefined
}, [resultsAndIndexDefined, searchResults, searchResultsIndex]);

const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0;

return (
<>
{getResultsNumberSpan()}
{resultsAndIndexDefined && cancerTypeResults.length > 0 && (
{resultsAndIndexDefined && searchResults.length > 0 && (
<div style={{ userSelect: "none", display: "flex" }}>
<div
data-type={PREV_BUTTON_DATA_TYPE}
className={clearIndicatorClass}
onClick={mobileView ? undefined : getPreviousResult}
onTouchStart={mobileView ? getPreviousResult : undefined}
onClick={isMobile ? undefined : getPreviousResult}
onTouchStart={isMobile ? getPreviousResult : undefined}
>
<FontAwesomeIcon
style={{ pointerEvents: "none" }}
Expand All @@ -348,8 +356,8 @@ export default function SearchBar({
<div
data-type={NEXT_BUTTON_DATA_TYPE}
className={clearIndicatorClass}
onClick={mobileView ? undefined : getNextResult}
onTouchStart={mobileView ? getNextResult : undefined}
onClick={isMobile ? undefined : getNextResult}
onTouchStart={isMobile ? getNextResult : undefined}
>
<FontAwesomeIcon
style={{ pointerEvents: "none" }}
Expand Down
Loading