diff --git a/package-lock.json b/package-lock.json index 0b11154266..70e88ee5ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9504,7 +9504,6 @@ "version": "15.7.2", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz", "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==", - "dev": true, "requires": { "loose-envify": "^1.4.0", "object-assign": "^4.1.1", @@ -9645,8 +9644,7 @@ "react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "dev": true + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "read-file-stdin": { "version": "0.2.1", diff --git a/package.json b/package.json index 4670c742dc..6cac8d4d5c 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "native-promise-only": "^0.8.0-a", "page": "^1.11.6", "pdfjs-dist": "2.6.347", + "prop-types": "^15.7.2", "react": "^17.0.2", "react-dom": "^17.0.2", "resize-observer-polyfill": "^1.5.1", diff --git a/src/components/pages/SearchPage.js b/src/components/pages/SearchPage.js new file mode 100644 index 0000000000..8bd9fa0bab --- /dev/null +++ b/src/components/pages/SearchPage.js @@ -0,0 +1,66 @@ +import PropTypes from 'prop-types'; +import React, { useEffect, useRef, useState } from 'react'; +import { Events } from 'jellyfin-apiclient'; + +import SearchFields from '../search/searchfields'; +import SearchResults from '../search/searchresults'; + +const SearchPage = ({ serverId, parentId, collectionType }) => { + const [ searchFields, setSearchFields ] = useState(null); + const searchFieldsContainer = useRef(null); + const [ searchResults, setSearchResults ] = useState(null); + const searchResultsContainer = useRef(null); + + useEffect(() => { + if (!searchFields) { + setSearchFields( + new SearchFields({ + element: searchFieldsContainer.current + }) + ); + + setSearchResults( + new SearchResults({ + element: searchResultsContainer.current, + serverId: serverId || ApiClient.serverId(), + parentId, + collectionType + }) + ); + } + + return () => { + searchFields?.destroy(); + searchResults?.destroy(); + }; + }, []); + + useEffect(() => { + if (searchFields) { + Events.on(searchFields, 'search', (e, value) => { + searchResults.search(value); + }); + } + }, [ searchFields ]); + + return ( + <> +
+ + > + ); +}; + +SearchPage.propTypes = { + serverId: PropTypes.string, + parentId: PropTypes.string, + collectionType: PropTypes.string +}; + +export default SearchPage; diff --git a/src/components/reactControllerFactory.js b/src/components/reactControllerFactory.js index 22aa48b388..5e2d46a950 100644 --- a/src/components/reactControllerFactory.js +++ b/src/components/reactControllerFactory.js @@ -7,7 +7,7 @@ export default (view, params, { detail }) => { if (detail.options?.pageComponent) { import(/* webpackChunkName: "[request]" */ `./pages/${detail.options.pageComponent}`) .then(({ default: component }) => { - ReactDOM.render(React.createElement(component), view); + ReactDOM.render(React.createElement(component, params), view); }); } }; diff --git a/src/controllers/search.html b/src/controllers/search.html index b0277aa7e0..e6fa92c0fc 100644 --- a/src/controllers/search.html +++ b/src/controllers/search.html @@ -1,4 +1,2 @@