From f8bb43ab9a2384c2203e9c7d81ae7471bde5e377 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 20 Nov 2023 11:05:48 +0100 Subject: [PATCH] feat: implement search history --- src/routes/Search/Search.js | 3 +++ src/routes/Search/useSearchHistory.d.ts | 2 ++ src/routes/Search/useSearchHistory.js | 10 ++++++++++ src/types/models/Ctx.d.ts | 3 +++ 4 files changed, 18 insertions(+) create mode 100644 src/routes/Search/useSearchHistory.d.ts create mode 100644 src/routes/Search/useSearchHistory.js diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index a2f5b758e..99f7d412e 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -8,6 +8,7 @@ const { useTranslation } = require('react-i18next'); const { default: Icon } = require('@stremio/stremio-icons/react'); const { Image, MainNavBars, MetaRow, MetaItem, withCoreSuspender, getVisibleChildrenRange } = require('stremio/common'); const useSearch = require('./useSearch'); +const useSearchHistory = require('./useSearchHistory'); const styles = require('./styles'); const THRESHOLD = 100; @@ -15,6 +16,8 @@ const THRESHOLD = 100; const Search = ({ queryParams }) => { const { t } = useTranslation(); const [search, loadSearchRows] = useSearch(queryParams); + const searchHistory = useSearchHistory(); + console.log(searchHistory); const query = React.useMemo(() => { return search.selected !== null ? search.selected.extra.reduceRight((query, [name, value]) => { diff --git a/src/routes/Search/useSearchHistory.d.ts b/src/routes/Search/useSearchHistory.d.ts new file mode 100644 index 000000000..5049b5046 --- /dev/null +++ b/src/routes/Search/useSearchHistory.d.ts @@ -0,0 +1,2 @@ +declare const useSearchHistory: () => SearchHistory; +export = useSearchHistory; \ No newline at end of file diff --git a/src/routes/Search/useSearchHistory.js b/src/routes/Search/useSearchHistory.js new file mode 100644 index 000000000..5c4833392 --- /dev/null +++ b/src/routes/Search/useSearchHistory.js @@ -0,0 +1,10 @@ +// Copyright (C) 2017-2023 Smart code 203358507 + +const useModelState = require('stremio/common/useModelState'); + +const useSearchHistory = () => { + const { searchHistory } = useModelState({ model: 'ctx' }); + return searchHistory; +}; + +module.exports = useSearchHistory; diff --git a/src/types/models/Ctx.d.ts b/src/types/models/Ctx.d.ts index 54ee1dc4e..ceb291cc7 100644 --- a/src/types/models/Ctx.d.ts +++ b/src/types/models/Ctx.d.ts @@ -56,7 +56,10 @@ type NotificationItem = { videoReleased: string, } +type SearchHistory = string[]; + type Ctx = { profile: Profile, notifications: Notifications, + searchHistory: SearchHistory, }; \ No newline at end of file