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 = [{}]) => {
items.map((i) => (
<ListItem>
<ListItemText primary={i.subject} />
</ListItem>
))
return <List></List>
}
items.map((i) => (
<ListItem key={i.thread_id}>
<ListItemText
primary={i.subject}
secondary={<React.Fragment>Hi There</React.Fragment>}
/>
</ListItem>
));
return <List></List>;
};

View file

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

View file

@ -1,6 +1,6 @@
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 }) => {
const handleThreadChange = (e, thread) => {
@ -12,6 +12,9 @@ export default ({ items = [{}], setThread }) => {
<ListItem button dense key={i.thread_id}>
<ListItemText
primary={i.subject}
secondary={i.tags.map((tag) => (
<Chip size="small" label={tag} />
))}
onClick={(e) => handleThreadChange(e, i)}
/>
</ListItem>

View file

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

View file

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