feat: Show last update time

This commit is contained in:
Rajarshee Chatterjee
2021-08-13 10:12:26 +05:30
parent e628c3cfd6
commit 5da3e05bba
9 changed files with 79 additions and 8 deletions
+14 -2
View File
@@ -15,7 +15,13 @@ export const Checkbox = ({ label, status, onPress, theme }) => (
style={styles.pressable}
onPress={onPress}
>
<Text style={{ color: theme.textColorPrimary }}>{label}</Text>
<Text
style={{
color: status ? theme.colorAccent : theme.textColorPrimary,
}}
>
{label}
</Text>
{status && (
<MaterialCommunityIcons
name="check"
@@ -40,7 +46,13 @@ export const SortItem = ({ label, status, onPress, theme }) => (
style={styles.pressable}
onPress={onPress}
>
<Text style={{ color: theme.textColorPrimary }}>{label}</Text>
<Text
style={{
color: status ? theme.colorAccent : theme.textColorPrimary,
}}
>
{label}
</Text>
{status && (
<MaterialCommunityIcons
name={status === "asc" ? "arrow-up" : "arrow-down"}
+3 -1
View File
@@ -1,4 +1,4 @@
import { GET_UPDATES } from "./updates.types";
import { GET_UPDATES, SET_LAST_UPDATE_TIME } from "./updates.types";
import { getUpdates } from "../../database/queries/UpdateQueries";
import { updateAllNovels } from "../../services/updates";
@@ -36,6 +36,8 @@ export const getUpdatesAction = () => async (dispatch) => {
export const updateLibraryAction = () => async (dispatch, getState) => {
showToast("Updating library");
dispatch({ type: SET_LAST_UPDATE_TIME, payload: Date.now() });
const { downloadNewChapters = false } = getState().settingsReducer;
await updateAllNovels({ downloadNewChapters });
+18 -1
View File
@@ -1,7 +1,14 @@
import { LOAD_UPDATES, GET_UPDATES } from "./updates.types";
import {
LOAD_UPDATES,
GET_UPDATES,
SET_LAST_UPDATE_TIME,
SHOW_LAST_UPDATE_TIME,
} from "./updates.types";
const initialState = {
updates: [],
lastUpdateTime: null,
showLastUpdateTime: true,
loading: true,
};
@@ -13,6 +20,16 @@ const updateReducer = (state = initialState, action) => {
return { ...state, loading: true };
case GET_UPDATES:
return { ...state, updates: payload, loading: false };
case SET_LAST_UPDATE_TIME:
return {
...state,
lastUpdateTime: payload,
};
case SHOW_LAST_UPDATE_TIME:
return {
...state,
showLastUpdateTime: payload,
};
default:
return state;
}
+2
View File
@@ -1,2 +1,4 @@
export const GET_UPDATES = "GET_UPDATES";
export const LOAD_UPDATES = "LOAD_UPDATES";
export const SET_LAST_UPDATE_TIME = "SET_LAST_UPDATE_TIME";
export const SHOW_LAST_UPDATE_TIME = "SHOW_LAST_UPDATE_TIME";
@@ -328,7 +328,11 @@ const ReaderSheet = ({
style={{
fontSize: 16,
fontFamily: font.fontFamily,
color: theme.textColorPrimary,
color:
reader.fontFamily ===
font.fontFamily
? theme.colorAccent
: theme.textColorPrimary,
}}
>
{font.name}
+16
View File
@@ -18,6 +18,7 @@ import {
import ColorPickerModal from "../../components/ColorPickerModal";
import SwitchSetting from "../../components/Switch/Switch";
import { ScrollView } from "react-native";
import { SHOW_LAST_UPDATE_TIME } from "../../redux/updates/updates.types";
const GenralSettings = ({ navigation }) => {
const theme = useTheme();
@@ -35,6 +36,10 @@ const GenralSettings = ({ navigation }) => {
showLabelsInNav = false,
} = useSettings();
const { showLastUpdateTime = true } = useSelector(
(state) => state.updatesReducer
);
const displayModeLabel = (displayMode) => {
const label = {
0: "Compact Grid",
@@ -165,6 +170,17 @@ const GenralSettings = ({ navigation }) => {
}
theme={theme}
/>
<SwitchSetting
label="Show last update time"
value={showLastUpdateTime}
onPress={() =>
dispatch({
type: SHOW_LAST_UPDATE_TIME,
payload: !showLastUpdateTime,
})
}
theme={theme}
/>
<List.Divider theme={theme} />
<List.SubHeader theme={theme}>Auto-download</List.SubHeader>
<SwitchSetting
+1
View File
@@ -95,6 +95,7 @@ const FirstRoute = React.memo(({ theme, dispatch, reader }) => {
<ScrollView
style={{ marginLeft: 16 }}
horizontal={true}
showsHorizontalScrollIndicator={false}
>
<Row>
{presetThemes.map((theme) => (
+2 -2
View File
@@ -99,10 +99,10 @@ const NovelInfoHeader = ({
{!loading && (
<>
<NovelAuthor theme={theme}>
{novel.author ?? "Unknown author"}
{novel.author || "Unknown author"}
</NovelAuthor>
<NovelInfo theme={theme}>
{novel.status ?? "Unknown status"}
{novel.status || "Unknown status"}
</NovelInfo>
<NovelInfo theme={theme}>
{novel.source}
+18 -1
View File
@@ -28,7 +28,12 @@ import {
const Updates = ({ navigation }) => {
const theme = useTheme();
const dispatch = useDispatch();
const { updates, loading } = useSelector((state) => state.updatesReducer);
const {
updates,
lastUpdateTime = null,
showLastUpdateTime = true,
loading,
} = useSelector((state) => state.updatesReducer);
const { downloadQueue } = useSelector((state) => state.downloadsReducer);
const [searchText, setSearchText] = useState("");
@@ -171,6 +176,18 @@ const Updates = ({ navigation }) => {
},
]}
/>
{showLastUpdateTime && lastUpdateTime && (
<Text
style={{
color: theme.textColorSecondary,
paddingHorizontal: 16,
paddingTop: 8,
textAlign: "center",
}}
>
Library last updated: {moment(lastUpdateTime).fromNow()}
</Text>
)}
<FlatList
contentContainerStyle={styles.flatList}
data={searchText ? searchResults : updates}