Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mobile version #117

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions src/tour.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -658,27 +658,36 @@ fn lesson_page_render(lesson: Lesson) -> String {
]),
static_content: [render_navbar()],
content: [
h("article", [#("id", "playground")], [
h("section", [#("id", "left"), #("class", "content-nav")], [
h("div", [], [
h("h2", [], [text(lesson.name)]),
htmb.dangerous_unescaped_fragment(string_builder.from_string(
lesson.text,
)),
h("main", [], [
h("article", [#("id", "playground"), #("class", "left")], [
h("section", [#("id", "left"), #("class", "content-nav")], [
h("div", [], [
h("h2", [], [text(lesson.name)]),
htmb.dangerous_unescaped_fragment(string_builder.from_string(
lesson.text,
)),
]),
]),
h("nav", [#("class", "prev-next")], [
navlink("Back", lesson.previous),
text(" — "),
h("a", [#("href", path_table_of_contents)], [text("Contents")]),
text(" — "),
navlink("Next", lesson.next),
h("section", [#("id", "right")], [
h("section", [#("id", "editor")], [
h("div", [#("id", "editor-target")], []),
]),
h("aside", [#("id", "output")], []),
]),
]),
h("section", [#("id", "right")], [
h("section", [#("id", "editor")], [
h("div", [#("id", "editor-target")], []),
]),
h("aside", [#("id", "output")], []),
h("nav", [#("class", "prev-next")], [
navlink("Back", lesson.previous),
text(" — "),
h("a", [#("href", path_table_of_contents)], [text("Contents")]),
text(" — "),
navlink("Next", lesson.next),
h("div", [#("id", "left-right-toggle"), #("class", "left")], [
text(" —"),
h("button",[#("class", "link")], [
h("span", [#("class", "left")], [text("See code")]),
h("span", [#("class", "right")], [text("See tutorial")]),
])
])
]),
]),
],
Expand Down
110 changes: 96 additions & 14 deletions static/css/pages/lesson.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#playground {
display: flex;
flex-direction: column;
flex-direction: row;
flex-grow: 1;
position: relative;
/* height of the prev-next area */
padding-bottom: 3.5rem;
height: 100%;
}

#playground.left #left {
display: flex;
}

#playground.right #right {
display: flex;
}

#left,
Expand All @@ -11,7 +23,7 @@
}

#right {
display: flex;
display: none;
flex-direction: column;
border: var(--color-divider);
background: var(--code-background);
Expand All @@ -21,6 +33,11 @@
min-height: fit-content;
}

#left, #right {
width: 100%;
display: none;
}

#output,
#editor {
border-top: 1px solid var(--color-accent-muted);
Expand All @@ -44,17 +61,74 @@
white-space: pre-wrap;
}

main {
flex: 1;
}

.prev-next {
display: flex;
z-index: 10;
justify-content: center;
align-items: center;
padding: 1rem var(--gap);
gap: 0.5em;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: var(--color-background);
border-top: 1px solid var(--color-accent-muted);
box-shadow: 0 0 5px 5px rgba(0, 0, 0, 0.1);
}

.prev-next span {
opacity: 0.5;
}


#left-right-toggle .left,
#left-right-toggle .right {
display: none;
opacity: 1;
}

#left-right-toggle button {
background: none;
padding: 0 0.5rem;

cursor: pointer;
font-size: var(--font-size-small);
border: none;
}

#left-right-toggle.left .left{
display: inline-block;
}
#left-right-toggle.right .right{
display: inline-block;
}

/* Larger then mobile */
@media (min-width: 768px) {
#playground {
min-height: calc(100dvh - var(--navbar-height));
flex-direction: row;
padding-bottom: 0;
height: auto;
}

/* any combination should show both sides */
#playground.left #left,
#playground.right #left,
#playground.right #right,
#playground.right #left {
display: flex;
}

#left {
height: 100%;
width: 50%;
overflow-y: auto;
padding-bottom: 3.5rem;

& h2:first-of-type {
margin-top: 0;
Expand All @@ -64,6 +138,15 @@
#right {
border-left: 1px solid var(--color-accent-muted);
width: 50%;
display: flex;
}

.prev-next {
width: 50%
}

#left-right-toggle {
display: none;
}

#editor {
Expand All @@ -81,6 +164,7 @@
#left {
/* Lift the navigation bar up a bit so it's not sitting right on the bottom*/
padding: calc(var(--gap) * 2);
padding-bottom: 3.5rem;
}

#right {
Expand All @@ -94,6 +178,15 @@
margin-bottom: calc(var(--gap) * 3);
margin-left: calc(var(--gap) * 2);
}

.prev-next {
width: 30%;
/* to center it */
margin-left: 10%;
border-radius: 10px 10px 0 0;
border: 1px solid var(--color-accent-muted);
border-bottom: 0;
}
}

.error,
Expand All @@ -111,17 +204,6 @@
border-color: var(--brand-warning);
}

.prev-next {
display: flex;
justify-content: center;
align-items: center;
padding: 0 var(--gap);
gap: 0.5em;
}

.prev-next span {
opacity: 0.5;
}

.mb-0 {
margin-bottom: 0;
Expand Down
18 changes: 18 additions & 0 deletions static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,21 @@ worker.onmessage = (event) => {
};

editor.onUpdate(debounce((code) => sendToWorker(code), 200));


function initLeftRightToggle() {
const toggle = document.querySelector("#left-right-toggle");
const btn = document.querySelector("#left-right-toggle button");
const playground = document.querySelector("#playground");

if (btn && toggle && right) {
btn.addEventListener(("click"), () => {
toggle.classList.toggle('left')
toggle.classList.toggle('right')
playground.classList.toggle('left')
playground.classList.toggle('right')
})
}
}

initLeftRightToggle();