diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2020-12-17 10:17:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-17 10:17:45 +0100 |
commit | 2f7ee2b82cda39f6bd94c5200b83563418b68dd7 (patch) | |
tree | 0942f00012ee7a90208c5d80ed3dd5ec6a3d9f92 /plugins/base/frontend/src/main | |
parent | 9e344b2047f72051bed509fb4e7ac1ae53f8098e (diff) | |
download | dokka-2f7ee2b82cda39f6bd94c5200b83563418b68dd7.tar.gz dokka-2f7ee2b82cda39f6bd94c5200b83563418b68dd7.tar.bz2 dokka-2f7ee2b82cda39f6bd94c5200b83563418b68dd7.zip |
Navigate to root after logo click, add data to searchbars on multimodule (#1631)
Diffstat (limited to 'plugins/base/frontend/src/main')
3 files changed, 33 insertions, 16 deletions
diff --git a/plugins/base/frontend/src/main/components/navigationPaneSearch/navigationPaneSearch.tsx b/plugins/base/frontend/src/main/components/navigationPaneSearch/navigationPaneSearch.tsx index b11b36f6..152e7719 100644 --- a/plugins/base/frontend/src/main/components/navigationPaneSearch/navigationPaneSearch.tsx +++ b/plugins/base/frontend/src/main/components/navigationPaneSearch/navigationPaneSearch.tsx @@ -4,6 +4,7 @@ import { DokkaFuzzyFilterComponent } from '../search/dokkaFuzzyFilter'; import { IWindow, Option } from '../search/types'; import './navigationPaneSearch.scss'; import ClearIcon from 'react-svg-loader!./clear.svg'; +import { relativizeUrlForRequest } from '../utils/requests'; export const NavigationPaneSearch = () => { const [navigationList, setNavigationList] = useState<Option[]>([]); @@ -31,9 +32,7 @@ export const NavigationPaneSearch = () => { } useEffect(() => { - const pathToRoot = (window as IWindow).pathToRoot - const url = pathToRoot.endsWith('/') ? `${pathToRoot}scripts/navigation-pane.json` : `${pathToRoot}/scripts/navigation-pane.json` - fetch(url) + fetch(relativizeUrlForRequest('scripts/navigation-pane.json')) .then(response => response.json()) .then((result) => { setNavigationList(result.map((record: Option, idx: number) => { diff --git a/plugins/base/frontend/src/main/components/search/search.tsx b/plugins/base/frontend/src/main/components/search/search.tsx index 3616a396..f0527cc0 100644 --- a/plugins/base/frontend/src/main/components/search/search.tsx +++ b/plugins/base/frontend/src/main/components/search/search.tsx @@ -1,10 +1,11 @@ -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { Select, List } from '@jetbrains/ring-ui'; import '@jetbrains/ring-ui/components/input-size/input-size.scss'; import './search.scss'; import { IWindow, Option, Props } from "./types"; import { DokkaSearchAnchor } from "./dokkaSearchAnchor"; import { DokkaFuzzyFilterComponent } from "./dokkaFuzzyFilter"; +import { relativizeUrlForRequest } from '../utils/requests'; const WithFuzzySearchFilterComponent: React.FC<Props> = ({ data }: Props) => { const [selected, onSelected] = useState<Option>(data[0]); @@ -42,17 +43,27 @@ const WithFuzzySearchFilterComponent: React.FC<Props> = ({ data }: Props) => { } export const WithFuzzySearchFilter = () => { - let data: Option[] = []; - const pages = (window as IWindow).pages; - if (pages) { - data = pages.map((page, i) => ({ - ...page, - label: page.name, - key: i + 1, - type: page.kind, - rgItemType: List.ListProps.Type.CUSTOM - })); - } + const [navigationList, setNavigationList] = useState<Option[]>([]); - return <WithFuzzySearchFilterComponent data={data} />; + useEffect(() => { + fetch(relativizeUrlForRequest('scripts/pages.json')) + .then(response => response.json()) + .then((result) => { + setNavigationList(result.map((record: Option, idx: number) => { + return { + ...record, + label: record.name, + key: idx, + type: record.kind, + rgItemType: List.ListProps.Type.CUSTOM + } + })) + }, + (error) => { + console.error('failed to fetch pages data', error) + setNavigationList([]) + }) + }, []) + + return <WithFuzzySearchFilterComponent data={navigationList} />; }; diff --git a/plugins/base/frontend/src/main/components/utils/requests.tsx b/plugins/base/frontend/src/main/components/utils/requests.tsx new file mode 100644 index 00000000..4a14e6f6 --- /dev/null +++ b/plugins/base/frontend/src/main/components/utils/requests.tsx @@ -0,0 +1,7 @@ +import { IWindow } from "../search/types" + +export const relativizeUrlForRequest = (filePath: string) : string => { + const pathToRoot = (window as IWindow).pathToRoot + const relativePath = pathToRoot == "" ? "." : pathToRoot + return relativePath.endsWith('/') ? `${relativePath}${filePath}` : `${relativePath}/${filePath}` +}
\ No newline at end of file |