Files
suwayomi-material-you-webui/src/components/reader/ReaderSettingsOptions.tsx

132 lines
5.7 KiB
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { List, ListItem, ListItemText, Switch } from '@mui/material';
import Select from '@mui/material/Select';
import MenuItem from '@mui/material/MenuItem';
import { useTranslation } from 'react-i18next';
import { AllowedMetadataValueTypes, IReaderSettings } from '@/typings';
import { NumberSetting } from '@/components/settings/NumberSetting.tsx';
Fix reader width (#567) * Fix reader width The margin: auto on the Box container for the image was preventing 100% width to actually mean 100%. Now that 100% is actually possible, I think fitPageToWindow makes more sense as a default. Additionally, since the image can fill 100% of the page, it can cover the ReaderNavBar, so set the z-index of the ReaderNavBar so it's rendered on top of the image and clickable. Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com> * Support configuring reader width for DoublePage readers Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com> * Fix single page of DoublePageReader not being able to take up full width In case the parent container is flex row, the container does not automatically take up 100% of the available width, thus, the page also was not able to take up 100% of the width * Fix applying reader width to double pages The set reader width can't be applied to each page of the double pages because otherwise it will already take up 100% of the available width with the setting only being at 50%. Instead, the set width has to be divided by 2, so that both pages take up the set reader width * Prevent double page spinner from being larger than 100% of the available width * Update width styling of the page spinner * Always center pages in the middle of the screen * Take up full height fitting page to window height --------- Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com> Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>
2024-01-26 11:51:08 -08:00
import { isHorizontalReaderType } from '@/components/reader/Page.tsx';
interface IProps extends IReaderSettings {
setSettingValue: (key: keyof IReaderSettings, value: AllowedMetadataValueTypes) => void;
}
2023-10-28 00:32:02 +02:00
export function ReaderSettingsOptions({
staticNav,
loadNextOnEnding,
readerType,
showPageNumber,
skipDupChapters,
setSettingValue,
fitPageToWindow,
offsetFirstPage,
readerWidth,
}: IProps) {
const { t } = useTranslation();
Fix reader width (#567) * Fix reader width The margin: auto on the Box container for the image was preventing 100% width to actually mean 100%. Now that 100% is actually possible, I think fitPageToWindow makes more sense as a default. Additionally, since the image can fill 100% of the page, it can cover the ReaderNavBar, so set the z-index of the ReaderNavBar so it's rendered on top of the image and clickable. Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com> * Support configuring reader width for DoublePage readers Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com> * Fix single page of DoublePageReader not being able to take up full width In case the parent container is flex row, the container does not automatically take up 100% of the available width, thus, the page also was not able to take up 100% of the width * Fix applying reader width to double pages The set reader width can't be applied to each page of the double pages because otherwise it will already take up 100% of the available width with the setting only being at 50%. Instead, the set width has to be divided by 2, so that both pages take up the set reader width * Prevent double page spinner from being larger than 100% of the available width * Update width styling of the page spinner * Always center pages in the middle of the screen * Take up full height fitting page to window height --------- Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com> Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>
2024-01-26 11:51:08 -08:00
const fitPageToWindowEligible = !isHorizontalReaderType(readerType);
return (
<List>
<ListItem>
<ListItemText primary={t('reader.settings.label.static_navigation')} />
<Switch
edge="end"
checked={staticNav}
onChange={(e) => setSettingValue('staticNav', e.target.checked)}
/>
</ListItem>
<ListItem>
<ListItemText primary={t('reader.settings.label.show_page_number')} />
<Switch
edge="end"
checked={showPageNumber}
onChange={(e) => setSettingValue('showPageNumber', e.target.checked)}
/>
</ListItem>
<ListItem>
<ListItemText primary={t('reader.settings.label.load_next_chapter')} />
<Switch
edge="end"
checked={loadNextOnEnding}
onChange={(e) => setSettingValue('loadNextOnEnding', e.target.checked)}
/>
</ListItem>
<ListItem>
<ListItemText primary={t('reader.settings.label.skip_dup_chapters')} />
<Switch
edge="end"
checked={skipDupChapters}
onChange={(e) => setSettingValue('skipDupChapters', e.target.checked)}
/>
</ListItem>
{fitPageToWindowEligible && (
<ListItem>
<ListItemText primary={t('reader.settings.label.fit_page_to_window')} />
<Switch
edge="end"
checked={fitPageToWindow}
onChange={(e) => setSettingValue('fitPageToWindow', e.target.checked)}
/>
</ListItem>
)}
{(readerType === 'DoubleLTR' || readerType === 'DoubleRTL') && (
<ListItem>
<ListItemText primary={t('reader.settings.label.offset_first_page')} />
<Switch
edge="end"
checked={offsetFirstPage}
onChange={(e) => setSettingValue('offsetFirstPage', e.target.checked)}
/>
</ListItem>
)}
{fitPageToWindowEligible && !fitPageToWindow && (
<NumberSetting
settingTitle={t('reader.settings.label.reader_width')}
settingValue={`${readerWidth}%`}
value={readerWidth}
minValue={10}
maxValue={100}
defaultValue={100}
valueUnit="%"
showSlider
handleUpdate={(width: number) => setSettingValue('readerWidth', width)}
listItemTextSx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}
/>
)}
<ListItem>
<ListItemText primary={t('reader.settings.label.reader_type')} />
<Select
variant="standard"
value={readerType}
onChange={(e) => setSettingValue('readerType', e.target.value)}
sx={{ p: 0 }}
>
<MenuItem value="SingleLTR">{t('reader.settings.reader_type.label.single_page_ltr')}</MenuItem>
<MenuItem value="SingleRTL">{t('reader.settings.reader_type.label.single_page_rtl')}</MenuItem>
{/* <MenuItem value="SingleVertical">
Vertical(WIP)
</MenuItem> */}
<MenuItem value="DoubleLTR">{t('reader.settings.reader_type.label.double_page_ltr')}</MenuItem>
<MenuItem value="DoubleRTL">{t('reader.settings.reader_type.label.double_page_rtl')}</MenuItem>
<MenuItem value="Webtoon">{t('reader.settings.reader_type.label.webtoon')}</MenuItem>
<MenuItem value="ContinuesVertical">
{t('reader.settings.reader_type.label.continuous_vertical')}
</MenuItem>
<MenuItem value="ContinuesHorizontalLTR">
{t('reader.settings.reader_type.label.continuous_horizontal_ltr')}
</MenuItem>
<MenuItem value="ContinuesHorizontalRTL">
{t('reader.settings.reader_type.label.continuous_horizontal_rtl')}
</MenuItem>
</Select>
</ListItem>
</List>
);
}