This commit is contained in:
Stefan Schwarz 2020-05-07 07:35:27 +02:00
parent e99de57edc
commit 3443227006
5 changed files with 27 additions and 16 deletions

View file

@ -1,10 +1,13 @@
import { List, ListItem, ListItemIcon, ListItemText } from '@material-ui/core' import { List, ListItem, ListItemIcon, ListItemText } from "@material-ui/core";
export default (items = [{}]) => { export default (items = [{}]) => {
items.map((i) => ( items.map((i) => (
<ListItem> <ListItem key={i.thread_id}>
<ListItemText primary={i.subject} /> <ListItemText
primary={i.subject}
secondary={<React.Fragment>Hi There</React.Fragment>}
/>
</ListItem> </ListItem>
)) ));
return <List></List> return <List></List>;
} };

View file

@ -12,9 +12,10 @@ export default function Index() {
const [threads, setThreads] = useState({ const [threads, setThreads] = useState({
count: 0, count: 0,
threads: [{}], threads: [],
}); });
useEffect(() => { useEffect(() => {
console.log(query);
fetch(`/search/${query}/0/30`) fetch(`/search/${query}/0/30`)
.then((response) => response.json()) .then((response) => response.json())
.then( .then(
@ -29,6 +30,7 @@ export default function Index() {
if (thread == "") { if (thread == "") {
return; return;
} }
console.log(threads);
fetch(`/thread/${thread}`) fetch(`/thread/${thread}`)
.then((response) => response.json()) .then((response) => response.json())
.then( .then(

View file

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import { List, ListItem, ListItemText } from "@material-ui/core"; import { Chip, List, ListItem, ListItemText } from "@material-ui/core";
export default ({ items = [{}], setThread }) => { export default ({ items = [{}], setThread }) => {
const handleThreadChange = (e, thread) => { const handleThreadChange = (e, thread) => {
@ -12,6 +12,9 @@ export default ({ items = [{}], setThread }) => {
<ListItem button dense key={i.thread_id}> <ListItem button dense key={i.thread_id}>
<ListItemText <ListItemText
primary={i.subject} primary={i.subject}
secondary={i.tags.map((tag) => (
<Chip size="small" label={tag} />
))}
onClick={(e) => handleThreadChange(e, i)} onClick={(e) => handleThreadChange(e, i)}
/> />
</ListItem> </ListItem>

View file

@ -7,16 +7,17 @@ import { Autocomplete } from "@material-ui/lab";
export default ({ setQuery }) => { export default ({ setQuery }) => {
const [search, setSearch] = useState(["tag:inbox"]); const [search, setSearch] = useState(["tag:inbox"]);
function handleSearchChange(event, value) { function handleSearchChange(_event, value) {
console.log(event);
console.log(value);
setSearch(value); setSearch(value);
setQuery(value.join(" ")); setQuery(value.join(" "));
} }
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
const handleSubSearchChange = (event, value, reason) => { const handleSubSearchChange = (_event, value, _reason) => {
const [kind, ...q] = value.split(":"); const [kind, ...q] = value.split(":");
if (q.length == 0) {
return;
}
const qq = q.join(":"); const qq = q.join(":");
fetch(`/autocomplete/${kind}/${qq}`) fetch(`/autocomplete/${kind}/${qq}`)
.then((response) => response.json()) .then((response) => response.json())
@ -36,6 +37,8 @@ export default ({ setQuery }) => {
<Autocomplete <Autocomplete
multiple multiple
id="search" id="search"
autoselect="true"
freeSolo="true"
value={search} value={search}
onChange={handleSearchChange} onChange={handleSearchChange}
onInputChange={handleSubSearchChange} onInputChange={handleSubSearchChange}
@ -46,7 +49,7 @@ export default ({ setQuery }) => {
size="small" size="small"
/> />
); );
}, [options]); }, [options, search]);
return autocomplete; return autocomplete;
}; };

View file

@ -94,7 +94,7 @@ async fn autocomplete(data: web::Data<Data>, req: HttpRequest) -> impl Responder
.take(1000) .take(1000)
.for_each(|msg| { .for_each(|msg| {
msg.tags().for_each(|tag| { msg.tags().for_each(|tag| {
results.insert(format!("tag:{}", tag)); results.insert(tag);
}) })
}), }),
Autocomplete::From => db Autocomplete::From => db