Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Use preact/signals utility component for option visibility
  • Loading branch information
siliconfeces committed Jun 17, 2026
commit e68ad677ef8cd11611907b71540ba87e5d3fff19
97 changes: 51 additions & 46 deletions public/js/mod/reader_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import { h, render } from "preact";
import { useState } from "preact/hooks";
import { computed } from "@preact/signals";
import { Show } from "@preact/signals/utils";
import htm from "htm";

import { state, stopAutoNextPage, toggleOverlay } from "./reader_common.js";
Expand Down Expand Up @@ -51,6 +53,9 @@ function SettingsPanel() {
state.preloadCount.value = preloadCount;
}

const notInfiniteScroll = computed(() => !state.infiniteScroll.value);
const isFitContainerMode = computed(() => state.fitMode.value === "fit-container");

return html`
<h2 class="ih" style="text-align:center">${I18N.ReaderOptions}</h2>
<h1 class="ih config-panel">${I18N.OptionsAutoSave}</h1>
Expand All @@ -62,46 +67,46 @@ function SettingsPanel() {
<${ToggleButton} id="fit-height" active=${state.fitMode.value === "fit-height"} onClick=${() => state.fitMode.value = "fit-height"} label=${I18N.FitHeight} />
</div>

${state.fitMode.value === "fit-container" && html`
<div id="container-width">
<h2 class="config-panel">${I18N.ContainerWidth}</h2>
<input id="container-width-input" class="stdinput" style="display:inline; width: 70%;" placeholder=${I18N.ContainerWidthDefaultValue} value=${containerWidth} onInput=${(e) => setContainerWidth(e.target.value)} />
<input id="container-width-apply" class="favtag-btn config-btn" type="button" style="display:inline;" onClick=${updateContainerWidth} value=${I18N.Apply} />
</div>
`}

${!state.infiniteScroll.value && html`
<div id="toggle-double-mode">
<h2 class="config-panel">${I18N.PageRendering}</h2>
<${ToggleButton} id="single-page" active=${!state.doublePageMode.value} onClick=${() => state.doublePageMode.value = false} label=${I18N.Single} />
<${ToggleButton} id="fit-width" active=${state.doublePageMode.value} onClick=${() => state.doublePageMode.value = true} label=${I18N.Double} />
</div>
`}

${!state.infiniteScroll.value && html`
<div id="toggle-manga-mode">
<h2 class="config-panel">${I18N.ReadingDirection}</h2>
<span class="config-panel"></span>
<${ToggleButton} id="normal-mode" active=${!state.mangaMode.value} onClick=${() => state.mangaMode.value = false} label=${I18N.LeftToRight} />
<${ToggleButton} id="manga-mode" active=${state.mangaMode.value} onClick=${() => state.mangaMode.value = true} label=${I18N.RightToLeft} />
</div>
`}

${!state.infiniteScroll.value && html`
<div id="preload-images">
<h2 class="config-panel">${I18N.HowManyToPreload}</h2>
<input id="preload-input" class="stdinput" style="display:inline" placeholder=${I18N.DefaultTwoImages} type="number" value=${preloadCount} onInput=${(e) => setPreloadCount(e.target.value)} />
<input id="preload-apply" class="favtag-btn config-btn" type="button" style="display:inline;" onClick=${updatePreloadCount} value=${I18N.Apply} />
</div>
`}

${!state.infiniteScroll.value && html`
<div id="toggle-header">
<h2 class="config-panel">${I18N.Header}</h2>
<${ToggleButton} id="show-header" active=${!state.hideHeader.value} onClick=${() => state.hideHeader.value = false} label=${I18N.Visible} />
<${ToggleButton} id="hide-header" active=${state.hideHeader.value} onClick=${() => state.hideHeader.value = true} label=${I18N.Hidden} />
</div>
`}
<${Show} when=${isFitContainerMode}>
<div id="container-width">
<h2 class="config-panel">${I18N.ContainerWidth}</h2>
<input id="container-width-input" class="stdinput" style="display:inline; width: 70%;" placeholder=${I18N.ContainerWidthDefaultValue} value=${containerWidth} onInput=${(e) => setContainerWidth(e.target.value)} />
<input id="container-width-apply" class="favtag-btn config-btn" type="button" style="display:inline;" onClick=${updateContainerWidth} value=${I18N.Apply} />
</div>
<//>

<${Show} when=${notInfiniteScroll}>
<div id="toggle-double-mode">
<h2 class="config-panel">${I18N.PageRendering}</h2>
<${ToggleButton} id="single-page" active=${!state.doublePageMode.value} onClick=${() => state.doublePageMode.value = false} label=${I18N.Single} />
<${ToggleButton} id="fit-width" active=${state.doublePageMode.value} onClick=${() => state.doublePageMode.value = true} label=${I18N.Double} />
</div>
<//>

<${Show} when=${notInfiniteScroll}>
<div id="toggle-manga-mode">
<h2 class="config-panel">${I18N.ReadingDirection}</h2>
<span class="config-panel"></span>
<${ToggleButton} id="normal-mode" active=${!state.mangaMode.value} onClick=${() => state.mangaMode.value = false} label=${I18N.LeftToRight} />
<${ToggleButton} id="manga-mode" active=${state.mangaMode.value} onClick=${() => state.mangaMode.value = true} label=${I18N.RightToLeft} />
</div>
<//>

<${Show} when=${notInfiniteScroll}>
<div id="preload-images">
<h2 class="config-panel">${I18N.HowManyToPreload}</h2>
<input id="preload-input" class="stdinput" style="display:inline" placeholder=${I18N.DefaultTwoImages} type="number" value=${preloadCount} onInput=${(e) => setPreloadCount(e.target.value)} />
<input id="preload-apply" class="favtag-btn config-btn" type="button" style="display:inline;" onClick=${updatePreloadCount} value=${I18N.Apply} />
</div>
<//>

<${Show} when=${notInfiniteScroll}>
<div id="toggle-header">
<h2 class="config-panel">${I18N.Header}</h2>
<${ToggleButton} id="show-header" active=${!state.hideHeader.value} onClick=${() => state.hideHeader.value = false} label=${I18N.Visible} />
<${ToggleButton} id="hide-header" active=${state.hideHeader.value} onClick=${() => state.hideHeader.value = true} label=${I18N.Hidden} />
</div>
<//>

<div id="toggle-overlay">
<h2 class="config-panel">${I18N.ShowArchiveOverlayByDefault}</h2>
Expand Down Expand Up @@ -130,12 +135,12 @@ function SettingsPanel() {
<input id="auto-next-page-apply" class="favtag-btn config-btn" type="button" style="display:inline;" onClick=${updateAutoNextPageInterval} value=${I18N.Apply} />
</div>

${!state.infiniteScroll.value && html`
<div id="toggle-stamps-visibility">
<h2 class="config-panel">${I18N.ToggleStamps}</h2>
<input id="toggle-stamps" class="fa" type="checkbox" checked=${state.markersVisible.value} onClick=${() => state.markersVisible.value = !state.markersVisible.value} />
</div>
`}
<${Show} when=${notInfiniteScroll}>
<div id="toggle-stamps-visibility">
<h2 class="config-panel">${I18N.ToggleStamps}</h2>
<input id="toggle-stamps" class="fa" type="checkbox" checked=${state.markersVisible.value} onClick=${() => state.markersVisible.value = !state.markersVisible.value} />
</div>
<//>
`;
}

Expand Down
1 change: 1 addition & 0 deletions templates/common/importmap.html.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"preact/compat": "[% c.url_for("/js/$version/vendor/compat.module.js") %]",
"@preact/signals": "[% c.url_for("/js/$version/vendor/signals.module.js") %]",
"@preact/signals-core": "[% c.url_for("/js/$version/vendor/signals-core.module.js") %]",
"@preact/signals/utils": "[% c.url_for("/js/$version/vendor/utils.module.js") %]",
"htm": "[% c.url_for("/js/$version/vendor/htm.js") %]",
"clsx": "[% c.url_for("/js/$version/vendor/clsx.m.js") %]",
"react-toastify": "[% c.url_for("/js/$version/vendor/react-toastify.esm.js") %]",
Expand Down
1 change: 1 addition & 0 deletions tools/install.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"/sortablejs/Sortable.min.js",
[ "/htm/dist/htm.mjs", "htm.js" ],
'/@preact/signals/dist/signals.module.js',
'/@preact/signals/utils/dist/utils.module.js',
'/@preact/signals-core/dist/signals-core.module.js',
);

Expand Down
Loading