mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
fix: Return to empty search on 'Search' sidebar click (#12115)
* fix: Return to empty search on 'Search' sidebar click * PR feedback
This commit is contained in:
@@ -4,6 +4,7 @@ import { useEffect, useState, useCallback, useMemo } from "react";
|
||||
import { DndProvider } from "react-dnd";
|
||||
import { HTML5Backend } from "react-dnd-html5-backend";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { metaDisplay } from "@shared/utils/keyboard";
|
||||
import Scrollable from "~/components/Scrollable";
|
||||
@@ -37,6 +38,15 @@ function AppSidebar() {
|
||||
const team = useCurrentTeam();
|
||||
const user = useCurrentUser();
|
||||
const can = usePolicy(team);
|
||||
const history = useHistory();
|
||||
|
||||
const handleSearchClick = useCallback(() => {
|
||||
const basePath = searchPath();
|
||||
const { pathname, search } = history.location;
|
||||
if (pathname.startsWith(basePath) && (search || pathname !== basePath)) {
|
||||
history.push(basePath);
|
||||
}
|
||||
}, [history]);
|
||||
|
||||
useEffect(() => {
|
||||
void collections.fetchAll();
|
||||
@@ -106,6 +116,7 @@ function AppSidebar() {
|
||||
icon={<SearchIcon />}
|
||||
label={t("Search")}
|
||||
exact={false}
|
||||
onClick={handleSearchClick}
|
||||
/>
|
||||
{can.createDocument && <DraftsLink />}
|
||||
</Section>
|
||||
|
||||
Reference in New Issue
Block a user