Allow setting default sort order for chapters (Closes #100)

This commit is contained in:
Rajarshee Chatterjee
2021-10-31 15:17:16 +05:30
parent a3d8aa5bcd
commit fd8fb367bd
5 changed files with 92 additions and 4 deletions
+1
View File
@@ -99,6 +99,7 @@ const initialState = {
*/
hideBackdrop: false,
defaultChapterSort: null,
/**
* Reader settings
+6 -3
View File
@@ -77,15 +77,18 @@ const Novel = ({route, navigation}) => {
const deleteDownloadsSnackbar = useModal();
const {
sort = 'ORDER BY chapterId ASC',
useFabForContinueReading = false,
defaultChapterSort = 'ORDER BY chapterId ASC',
} = useSettings();
const {
sort = defaultChapterSort,
filter = '',
showChapterTitles = false,
} = usePreferences(novel.novelId);
let {lastReadChapter, position} = useContinueReading(chapters, novel.novelId);
const {useFabForContinueReading = lastReadChapter && false} = useSettings();
useEffect(() => {
dispatch(
getNovelAction(followed, sourceId, novelUrl, novelId, sort, filter),
@@ -89,7 +89,7 @@ const JumpToChapterModal = ({
<TextInput
value={text}
placeholder={
mode ? 'Chapter Name' : `Chapter Number (<= ${chapters.length})`
mode ? 'Chapter Name' : `Chapter Number (≤ ${chapters.length})`
}
onChangeText={onChangeText}
onSubmitEditing={onSubmit}
@@ -14,6 +14,7 @@ import {useSettings, useTheme} from '../../hooks/reduxHooks';
import {setAppSettings} from '../../redux/settings/settings.actions';
import {SHOW_LAST_UPDATE_TIME} from '../../redux/updates/updates.types';
import {useModal} from '../../hooks/useModal';
import DefaultChapterSortModal from './components/DefaultChapterSortModal';
const GenralSettings = ({navigation}) => {
const theme = useTheme();
@@ -27,6 +28,7 @@ const GenralSettings = ({navigation}) => {
updateLibraryOnLaunch = false,
downloadNewChapters = false,
onlyUpdateOngoingNovels = false,
defaultChapterSort = 'ORDER BY chapterId ASC',
} = useSettings();
const {showLastUpdateTime = true} = useSelector(
@@ -54,6 +56,8 @@ const GenralSettings = ({navigation}) => {
*/
const gridSizeModalRef = useModal();
const defaultChapterSortModal = useModal();
return (
<ScreenContainer theme={theme}>
<Appbar title="General" onBackAction={navigation.goBack} />
@@ -85,6 +89,18 @@ const GenralSettings = ({navigation}) => {
theme={theme}
/>
<List.Divider theme={theme} />
<List.SubHeader theme={theme}>Novel</List.SubHeader>
<List.Item
title="Default chapter sort"
description={`By source ${
defaultChapterSort === 'ORDER BY chapterId ASC'
? '(Ascending)'
: '(Descending)'
}`}
onPress={defaultChapterSortModal.showModal}
theme={theme}
/>
<List.Divider theme={theme} />
<List.SubHeader theme={theme}>Global update</List.SubHeader>
<SwitchSetting
label="Only update ongoing novels"
@@ -131,6 +147,13 @@ const GenralSettings = ({navigation}) => {
dispatch={dispatch}
theme={theme}
/>
<DefaultChapterSortModal
defaultChapterSort={defaultChapterSort}
displayModalVisible={defaultChapterSortModal.visible}
hideDisplayModal={defaultChapterSortModal.hideModal}
dispatch={dispatch}
theme={theme}
/>
<GridSizeModal
dispatch={dispatch}
novelsPerRow={novelsPerRow}
@@ -0,0 +1,61 @@
import React from 'react';
import {StyleSheet} from 'react-native';
import {Portal, Modal} from 'react-native-paper';
import {SortItem} from '../../../components/Checkbox/Checkbox';
import {setAppSettings} from '../../../redux/settings/settings.actions';
const DefaultChapterSortModal = ({
theme,
dispatch,
defaultChapterSort,
hideDisplayModal,
displayModalVisible,
}) => {
return (
<Portal>
<Modal
visible={displayModalVisible}
onDismiss={hideDisplayModal}
contentContainerStyle={[
styles.containerStyle,
{backgroundColor: theme.colorPrimaryDark},
]}
>
<SortItem
label="By source"
theme={theme}
status={
defaultChapterSort === 'ORDER BY chapterId ASC' ? 'asc' : 'desc'
}
onPress={() =>
defaultChapterSort === 'ORDER BY chapterId ASC'
? dispatch(
setAppSettings(
'defaultChapterSort',
'ORDER BY chapterId DESC',
),
)
: dispatch(
setAppSettings(
'defaultChapterSort',
'ORDER BY chapterId ASC',
),
)
}
/>
</Modal>
</Portal>
);
};
export default DefaultChapterSortModal;
const styles = StyleSheet.create({
containerStyle: {
paddingVertical: 20,
margin: 20,
borderRadius: 6,
},
});