Skip to content

Commit

Permalink
Navigate to previous page when canceling search
Browse files Browse the repository at this point in the history
This makes the search the next page in the history stack instead of making it the previous one
  • Loading branch information
schroda committed Nov 12, 2023
1 parent fd6d389 commit 0b14f36
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/components/util/AppbarSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IconButton, Input, Tooltip } from '@mui/material';
import CancelIcon from '@mui/icons-material/Cancel';
import { useQueryParam, StringParam } from 'use-query-params';
import { useTranslation } from 'react-i18next';
import { useBackButton } from '@/util/useBackButton.ts';

interface IProps {
autoOpen?: boolean;
Expand All @@ -23,6 +24,7 @@ const defaultProps = {

export const AppbarSearch: React.FunctionComponent<IProps> = (props) => {
const { t } = useTranslation();
const handleBack = useBackButton();

const { autoOpen } = props;
const [query, setQuery] = useQueryParam('query', StringParam);
Expand All @@ -38,6 +40,8 @@ export const AppbarSearch: React.FunctionComponent<IProps> = (props) => {
const cancelSearch = () => {
setSearchString('');
setSearchOpen(false);

handleBack();
};
const handleBlur = () => {
if (!searchString) setSearchOpen(false);
Expand Down
4 changes: 3 additions & 1 deletion src/screens/SearchAll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { AppbarSearch } from '@/components/util/AppbarSearch';
import { LangSelect } from '@/components/navbar/action/LangSelect';
import { MangaGrid } from '@/components/MangaGrid';
import { useDebounce } from '@/components/manga/hooks';
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext.tsx';

type SourceLoadingState = { isLoading: boolean; hasResults: boolean; emptySearch: boolean };
type SourceToLoadingStateMap = Map<string, SourceLoadingState>;
Expand Down Expand Up @@ -161,6 +161,8 @@ export const SearchAll: React.FC = () => {

const { setTitle, setAction } = useContext(NavBarContext);

useSetDefaultBackTo('sources/all/search');

const [query] = useQueryParam('query', StringParam);
const searchString = useDebounce(query, TRIGGER_SEARCH_THRESHOLD);

Expand Down
17 changes: 11 additions & 6 deletions src/screens/SourceMangas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
GetSourceMangasFetchMutation,
GetSourceMangasFetchMutationVariables,
} from '@/lib/graphql/generated/graphql.ts';
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext.tsx';

const ContentTypeMenu = styled('div')(({ theme }) => ({
display: 'flex',
Expand Down Expand Up @@ -198,21 +198,26 @@ const useSourceManga = (
export function SourceMangas() {
const { t } = useTranslation();
const { setTitle, setAction } = useContext(NavBarContext);

const theme = useTheme();
const isLargeScreen = useMediaQuery(theme.breakpoints.up('sm'));

const { sourceId } = useParams<{ sourceId: string }>();

const navigate = useNavigate();
const { pathname, state: locationState } =
useLocation<{
contentType: SourceContentType;
filtersToApply: IPos[];
clearCache: boolean;
}>() ?? {};
const {
contentType: currentLocationContentType = SourceContentType.POPULAR,
filtersToApply: currentLocationFiltersToApply = [],
clearCache = false,
} = useLocation<{
contentType: SourceContentType;
filtersToApply: IPos[];
clearCache: boolean;
}>().state ?? {};
} = locationState ?? {};

useSetDefaultBackTo(pathname);

const { options } = useLibraryOptionsContext();
const [query] = useQueryParam('query', StringParam);
Expand Down

0 comments on commit 0b14f36

Please sign in to comment.