This commit is contained in:
thuhole
2020-07-21 17:35:15 +08:00
parent 7636e45c00
commit 98881eca9a
17 changed files with 4541 additions and 3621 deletions

View File

@@ -60,15 +60,32 @@ class App extends Component {
this.setState((prevState) => {
let ns = prevState.sidebar_stack.slice();
if (mode === 'push') {
if (ns.length === 1) {
document.body.style.top = `-${window.scrollY}px`;
document.body.style.position = 'fixed';
document.body.style.width = '100vw'; // Be responsive with fixed position
}
if (ns.length > MAX_SIDEBAR_STACK_SIZE) ns.splice(1, 1);
ns = ns.concat([[title, content]]);
} else if (mode === 'pop') {
if (ns.length === 1) return;
if (ns.length === 2) {
const scrollY = document.body.style.top;
document.body.style.position = '';
document.body.style.top = '';
document.body.style.width = '';
window.scrollTo(0, parseInt(scrollY || '0') * -1);
}
ns.pop();
} else if (mode === 'replace') {
ns.pop();
ns = ns.concat([[title, content]]);
} else if (mode === 'clear') {
const scrollY = document.body.style.top;
document.body.style.position = '';
document.body.style.top = '';
document.body.style.width = '';
window.scrollTo(0, parseInt(scrollY || '0') * -1);
ns = [[null, null]];
} else throw new Error('bad show_sidebar mode');
return {
@@ -103,6 +120,7 @@ class App extends Component {
<Title
show_sidebar={this.show_sidebar_bound}
set_mode={this.set_mode_bound}
mode={this.state.mode}
/>
<TokenCtx.Consumer>
{(token) => (