Skip to content

Commit

Permalink
allow to click on partial search result (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau authored Dec 17, 2023
2 parents ce8350e + e4c7f3c commit 0a0d3e6
Show file tree
Hide file tree
Showing 5 changed files with 1,970 additions and 6 deletions.
2 changes: 1 addition & 1 deletion papyri-lab/papyri_lab/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def post(self):
self.finish(
json.dumps(
{
"data": [c.path for c in candidates[:10]],
"data": [c.path for c in candidates[:50]],
"body": body,
}
)
Expand Down
27 changes: 24 additions & 3 deletions papyri-lab/src/widgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ const PapyriComponent = (): JSX.Element => {
// the current query
const [possibilities, setPossibilities] = useState([]);
const [root, setRoot] = useState({});
const [what, setWhat] = useState('');

// callback when typing in the input field.
const onChange = async (event: any) => {
setWhat(event.target.value);
search(event.target.value);
};
const search = async (query: string) => {
const res = await requestAPI<any>('get-example', {
body: event.target.value,
body: query,
method: 'post'
});
// response has body (MyST–json if the query has an exact match)
Expand All @@ -37,12 +42,28 @@ const PapyriComponent = (): JSX.Element => {
}
};

const onClick = (value: string) => {
setWhat(value);
try {
search(value);
} catch (e) {
console.error(e);
}
return false;
};

return (
<React.StrictMode>
<input onChange={onChange} />
<input onChange={onChange} value={what} />
<ul>
{possibilities.map(e => {
return <li>{e}</li>;
return (
<li>
<a href={e} onClick={() => onClick(e)}>
{e}
</a>
</li>
);
})}
</ul>
<ThemeProvider renderers={RENDERERS}>
Expand Down
1,940 changes: 1,939 additions & 1 deletion papyri-lab/style/app.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions papyri-lab/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ code {
.not-implemented {
border: 1px solid orange;
}

div#papyri-browser a:hover {
text-decoration: underline;
}
3 changes: 2 additions & 1 deletion papyri/crosslink.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ def ingest(self, path: Path, check: bool) -> None:
)
assert hasattr(nvisited_items[qa], "arbitrary")
except Exception as e:
raise RuntimeError(f"error Reading to {f1}") from e
e.add_note(f"error Reading to {f1}")
raise

# known_refs_II = frozenset(nvisited_items.keys())

Expand Down

0 comments on commit 0a0d3e6

Please sign in to comment.