mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Apps and tags are suggested in global search.
This commit is contained in:
parent
d042b06e8b
commit
fdfb8797fe
7 changed files with 68 additions and 15 deletions
|
|
@ -158,7 +158,7 @@ export function DashboardPage() {
|
|||
const navigate = useNavigate();
|
||||
|
||||
const {searchStr, setSearchStr, activeTags} = useSearch();
|
||||
const {suggestions} = useSearchSuggestions();
|
||||
const {suggestions, handleResultSelect} = useSearchSuggestions();
|
||||
const {status} = useContext(StatusContext);
|
||||
|
||||
let title = 'Dashboard';
|
||||
|
|
@ -198,6 +198,7 @@ export function DashboardPage() {
|
|||
onClear={() => navigate('/')}
|
||||
style={{marginBottom: '2em'}}
|
||||
results={suggestions}
|
||||
handleResultSelect={handleResultSelect}
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={3} textAlign='right'>
|
||||
|
|
@ -220,6 +221,7 @@ export function DashboardPage() {
|
|||
onClear={() => navigate('/')}
|
||||
style={{marginBottom: '2em'}}
|
||||
results={suggestions}
|
||||
handleResultSelect={handleResultSelect}
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column textAlign='right' width={2}>
|
||||
|
|
|
|||
|
|
@ -1026,9 +1026,11 @@ export async function searchSuggestions(search_str) {
|
|||
const content = await response.json();
|
||||
const channels = content['channels'];
|
||||
const domains = content['domains'];
|
||||
const tags = content['tags'];
|
||||
return {
|
||||
channels,
|
||||
domains,
|
||||
tags,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -413,10 +413,10 @@ export function SearchInput({
|
|||
onClear = null,
|
||||
onChange = null,
|
||||
results = null,
|
||||
handleResultSelect = null,
|
||||
...props
|
||||
}) {
|
||||
const [value, setValue] = useState(searchStr || '');
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleChange = (e) => {
|
||||
if (e) {
|
||||
|
|
@ -455,19 +455,13 @@ export function SearchInput({
|
|||
}
|
||||
}
|
||||
|
||||
const localHandleResultSelect = (e, {result}) => {
|
||||
const localHandleResultSelect = (e, data) => {
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result['type'] === 'channel') {
|
||||
navigate(`/videos/channel/${result['id']}/video`);
|
||||
} else if (result['type'] === 'domain') {
|
||||
navigate(`/archive?domain=${result['domain']}`);
|
||||
console.debug(`Selected result`, data);
|
||||
if (handleResultSelect) {
|
||||
handleResultSelect(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,19 @@ import {searchEstimate, searchSuggestions} from "../api";
|
|||
import {normalizeEstimate, TabLinks} from "./Common";
|
||||
import _ from "lodash";
|
||||
|
||||
const suggestedApps = [
|
||||
{location: '/more/otp', title: 'One Time Pad', description: 'Encrypt and Decrypt messages'},
|
||||
{location: '/inventory', title: 'Inventory', description: 'Track and organize your food storage'},
|
||||
{location: '/more/vin', title: 'Vin Decoder', description: 'Decode and analyze vehicle VIN numbers'},
|
||||
{location: '/admin', title: 'Downloads', description: 'View your downloads'},
|
||||
{location: '/admin/settings', title: 'Settings', description: 'View and modify your settings'},
|
||||
{location: '/admin/wrol', title: 'WROL Mode', description: 'Enable or disable WROL Mode'},
|
||||
];
|
||||
|
||||
export function useSearchSuggestions() {
|
||||
const navigate = useNavigate();
|
||||
const {searchParams} = useQuery();
|
||||
|
||||
const searchStr = searchParams.get('q');
|
||||
|
||||
const [suggestions, setSuggestions] = useState(null);
|
||||
|
|
@ -17,6 +28,7 @@ export function useSearchSuggestions() {
|
|||
if (searchStr && searchStr.length > 0) {
|
||||
try {
|
||||
const i = await searchSuggestions(searchStr);
|
||||
const matchingApps = suggestedApps.filter(i => i.title.toLowerCase().includes(searchStr));
|
||||
const newSuggestions = {
|
||||
channels: {
|
||||
name: 'Channels', results: i['channels'].map(i => {
|
||||
|
|
@ -28,6 +40,12 @@ export function useSearchSuggestions() {
|
|||
return {title: i['domain'], id: i['id'], type: 'domain'}
|
||||
})
|
||||
},
|
||||
tags: {
|
||||
name: 'Tags', results: i['tags'].map(i => {
|
||||
return {title: i['name'], type: 'tag'}
|
||||
})
|
||||
},
|
||||
apps: {name: 'Apps', results: matchingApps},
|
||||
};
|
||||
console.debug('newSuggestions', newSuggestions);
|
||||
setSuggestions(newSuggestions);
|
||||
|
|
@ -44,7 +62,24 @@ export function useSearchSuggestions() {
|
|||
fetchSuggestions();
|
||||
}, [searchStr]);
|
||||
|
||||
return {suggestions, searchStr}
|
||||
|
||||
const handleResultSelect = ({result}) => {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.location) {
|
||||
navigate(result.location);
|
||||
} else if (result['type'] === 'channel') {
|
||||
navigate(`/videos/channel/${result['id']}/video`);
|
||||
} else if (result['type'] === 'domain') {
|
||||
navigate(`/archive?domain=${result['domain']}`);
|
||||
} else if (result['type'] === 'tag') {
|
||||
navigate(`/search?tag=${result['title']}`);
|
||||
}
|
||||
}
|
||||
|
||||
return {suggestions, searchStr, handleResultSelect}
|
||||
}
|
||||
|
||||
export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false, model) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue