Skip to content

Commit

Permalink
Live doc search (#547)
Browse files Browse the repository at this point in the history
Co-authored-by: Fons van der Plas <[email protected]>
  • Loading branch information
iboss-ptk and fonsp authored Oct 14, 2020
1 parent 7a844dd commit 04a984e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 16 deletions.
37 changes: 31 additions & 6 deletions frontend/components/LiveDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RawHTMLContainer, highlight_julia } from "./CellOutput.js"

export let LiveDocs = ({ desired_doc_query, client, on_update_doc_query, notebook }) => {
let container_ref = useRef()
let live_doc_search_ref = useRef()
let [state, set_state] = useState({
shown_query: null,
searched_query: null,
Expand Down Expand Up @@ -54,12 +55,11 @@ export let LiveDocs = ({ desired_doc_query, client, on_update_doc_query, noteboo
}

if (state.searched_query !== desired_doc_query) {
fetch_docs()
fetch_docs(desired_doc_query)
}
}, [desired_doc_query])
}, [desired_doc_query, state.hidden])

let fetch_docs = () => {
const new_query = desired_doc_query
let fetch_docs = (new_query) => {
update_state((state) => {
state.loading = true
state.searched_query = new_query
Expand Down Expand Up @@ -90,8 +90,33 @@ export let LiveDocs = ({ desired_doc_query, client, on_update_doc_query, noteboo
return html`
<aside id="helpbox-wrapper" ref=${container_ref}>
<pluto-helpbox class=${cl({ hidden: state.hidden, loading: state.loading })}>
<header onClick=${() => set_state((state) => ({ ...state, hidden: !state.hidden }))}>
${state.hidden || state.searched_query == null ? "Live docs" : state.searched_query}
<header
onClick=${() => {
if (state.hidden) {
set_state((state) => ({ ...state, hidden: false }))
// wait for next event loop
setTimeout(() => live_doc_search_ref.current && live_doc_search_ref.current.focus(), 0)
}
}}
>
${state.hidden
? "Live docs"
: html`
<input
id="live-docs-search"
placeholder="Live docs"
ref=${live_doc_search_ref}
onInput=${(e) => fetch_docs(e.target.value)}
value=${state.searched_query}
type="text"
></input>
<button onClick=${(e) => {
set_state((state) => ({ ...state, hidden: true }))
e.stopPropagation()
console.log(state)
setTimeout(() => live_doc_search_ref.current && live_doc_search_ref.current.focus(), 0)
}}><span></span></button>
`}
</header>
<section ref=${(ref) => ref != null && resolve_doc_reference_links(ref, on_update_doc_query)}>
<h1><code>${state.shown_query}</code></h1>
Expand Down
57 changes: 47 additions & 10 deletions frontend/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ main {
@media screen and (min-width: calc(700px + 25px + 6px + 350px)) and (max-width: calc(700px + 25px + 6px + 500px)) {
main {
margin-left: 0px;
align-self: flex-start;
}
}
@media screen and (min-width: calc(700px + 25px + 6px + 500px)) and (max-width: calc(700px + 25px + 6px + 500px + 500px)) {
Expand Down Expand Up @@ -1168,17 +1169,60 @@ dropruler {
box-shadow: 0 0 11px 0px #00000010;
font-family: "Alegreya Sans", sans-serif;
}

pluto-helpbox > header {
display: flex;
padding: 15px;
background-color: #eef1f7;
color: hsl(230, 14%, 11%);
font-family: "Roboto Mono", monospace;
font-weight: 700;
cursor: pointer;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
/* border-top: 4px solid #8a8a8a; */
}
pluto-helpbox > header::before {
content: "πŸ“– ";
margin-right: 10px;
}
/* pluto-helpbox.loading>header::before{
content: "βŒ› ";
margin-right: 10px;
} */
pluto-helpbox.hidden > header::before {
content: "πŸ“š ";
margin-right: 10px;
}
pluto-helpbox > header > input {
flex-grow: 1;
background-color: inherit;
color: inherit;
font-family: inherit;
font-weight: inherit;
font-size: inherit;
border: none;
}
pluto-helpbox > header > input:focus {
outline: none;
}
pluto-helpbox > header > button {
border: none;
background: none;
cursor: pointer;

/* for bigger hitbox */
margin: -15px;
border: 15px solid transparent;
}
pluto-helpbox > header > button > span {
display: block;
content: " " !important;
background-size: 1em 1em;
height: 1em;
width: 1em;
background-image: url("https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/chevron-down-outline.svg");
}

pluto-helpbox > section {
height: 100%;
overflow: auto;
Expand All @@ -1202,19 +1246,12 @@ dropruler {
}
pluto-helpbox.hidden {
height: initial;
cursor: pointer;
}
pluto-helpbox.hidden > section {
display: none;
}
pluto-helpbox > header::before {
content: "πŸ“– ";
}
/* pluto-helpbox.loading>header::before{
content: "βŒ› ";
} */
pluto-helpbox.hidden > header::before {
content: "πŸ“š ";
}

}

/* FOOTER */
Expand Down

0 comments on commit 04a984e

Please sign in to comment.