| 1 | // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt |
| 2 | |
| 3 | import { newDialog } from './dialog' |
| 4 | import { state, useSnapState } from './state' |
| 5 | import { createElement as h } from 'react' |
| 6 | import { Checkbox, FlexV, Select } from './components' |
| 7 | import { getHFS, hIcon, MAX_TILE_SIZE, SORT_BY_OPTIONS, THEME_OPTIONS } from './misc' |
| 8 | import { MenuLink } from './menu' |
| 9 | import _ from 'lodash' |
| 10 | import i18n from './i18n' |
| 11 | const { t, useI18N } = i18n |
| 12 | |
| 13 | export function showOptions (){ |
| 14 | newDialog({ |
| 15 | title: t`Options`, |
| 16 | className: 'options-dialog', |
| 17 | icon: () => hIcon('options'), |
| 18 | Content |
| 19 | }) |
| 20 | |
| 21 | function Content(){ |
| 22 | const snap = useSnapState() |
| 23 | const {t} = useI18N() |
| 24 | return h(FlexV, { gap: '1.5em' }, |
| 25 | snap.adminUrl && h(MenuLink, { |
| 26 | id: 'admin-link', |
| 27 | icon: 'admin', |
| 28 | label: t`Admin-panel`, |
| 29 | href: snap.adminUrl, |
| 30 | target: 'admin', |
| 31 | }), |
| 32 | h(Select, { |
| 33 | id: 'option-sort-by', |
| 34 | options: SORT_BY_OPTIONS.map(x => ({ |
| 35 | value: x, |
| 36 | label: t("Sort by:", { by: t(x) }, t`Sort by` + ': ' + t(x)) |
| 37 | })), |
| 38 | value: snap.sort_by, |
| 39 | onChange(v) { state.sort_by = v } |
| 40 | }), |
| 41 | h(Checkbox, { |
| 42 | id: 'option-invert-order', |
| 43 | value: snap.invert_order, |
| 44 | onChange(v) { state.invert_order = v } |
| 45 | }, t`Invert order`), |
| 46 | h(Checkbox, { |
| 47 | id: 'option-folders-first', |
| 48 | value: snap.folders_first, |
| 49 | onChange(v) { state.folders_first = v } |
| 50 | }, t`Folders first`), |
| 51 | h(Checkbox, { |
| 52 | id: 'option-sort-numerics', |
| 53 | value: snap.sort_numerics, |
| 54 | onChange(v) { state.sort_numerics = v } |
| 55 | }, t`Numeric names`), |
| 56 | |
| 57 | h('div', { id: 'option-tile-size' }, |
| 58 | h('div', {}, t`Tiles mode:`, ' ', state.tile_size || t`off`), |
| 59 | h('input', { |
| 60 | type: 'range', |
| 61 | min: 0, max: MAX_TILE_SIZE, |
| 62 | value: snap.tile_size, |
| 63 | onChange(ev: any) { |
| 64 | state.tile_size = Number(ev.target.value) |
| 65 | } |
| 66 | }), |
| 67 | ), |
| 68 | |
| 69 | !getHFS().forceTheme && h(Select, { |
| 70 | id: 'option-theme', |
| 71 | options: _.map(THEME_OPTIONS, (value, label) => ({ label: t(["theme:", "Theme:", ]) + ' ' + t(label), value })), |
| 72 | value: snap.theme, |
| 73 | onChange(v) { |
| 74 | state.theme = v |
| 75 | } |
| 76 | }), |
| 77 | |
| 78 | !_.isEmpty(getHFS().lang) && h(Checkbox, { |
| 79 | id: 'option-english', |
| 80 | value: snap.disableTranslation, |
| 81 | onChange(v) { |
| 82 | i18n.state.disabled = state.disableTranslation = v |
| 83 | } |
| 84 | }, "English"), |
| 85 | ) |
| 86 | } |
| 87 | } |