2022-08-31 06:33:37 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
2023-01-16 13:44:52 +05:00
|
|
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
2022-08-31 06:33:37 +05:00
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-08-30 16:13:11 +05:00
|
|
|
|
2024-02-29 23:26:58 +05:00
|
|
|
import { useThemeColors } from "@notesnook/theme";
|
|
|
|
|
import { useNetInfo } from "@react-native-community/netinfo";
|
2022-08-26 16:19:39 +05:00
|
|
|
import dayjs from "dayjs";
|
2022-08-29 16:19:17 +05:00
|
|
|
import React from "react";
|
2024-02-29 23:26:58 +05:00
|
|
|
import { Image, TouchableOpacity, View } from "react-native";
|
|
|
|
|
import ImagePicker from "react-native-image-crop-picker";
|
2022-08-26 16:19:39 +05:00
|
|
|
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
|
2024-02-29 23:26:58 +05:00
|
|
|
import { db } from "../../common/database";
|
|
|
|
|
import { presentDialog } from "../../components/dialog/functions";
|
|
|
|
|
import AppIcon from "../../components/ui/AppIcon";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { TimeSince } from "../../components/ui/time-since";
|
|
|
|
|
import Heading from "../../components/ui/typography/heading";
|
|
|
|
|
import Paragraph from "../../components/ui/typography/paragraph";
|
2024-02-29 23:26:58 +05:00
|
|
|
import { useThemeStore } from "../../stores/use-theme-store";
|
2024-02-05 12:14:45 +05:00
|
|
|
import { SyncStatus, useUserStore } from "../../stores/use-user-store";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { SUBSCRIPTION_STATUS_STRINGS } from "../../utils/constants";
|
|
|
|
|
import { SIZE } from "../../utils/size";
|
|
|
|
|
import { SectionItem } from "./section-item";
|
2024-07-27 10:19:43 +05:00
|
|
|
import { strings } from "@notesnook/intl";
|
2024-02-05 12:14:45 +05:00
|
|
|
|
2022-08-26 16:19:39 +05:00
|
|
|
export const getTimeLeft = (t2) => {
|
|
|
|
|
let daysRemaining = dayjs(t2).diff(dayjs(), "days");
|
2021-11-24 09:57:23 +05:00
|
|
|
return {
|
2022-08-26 16:19:39 +05:00
|
|
|
time: dayjs(t2).diff(dayjs(), daysRemaining === 0 ? "hours" : "days"),
|
2021-11-24 09:57:23 +05:00
|
|
|
isHour: daysRemaining === 0
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-26 08:57:04 +05:00
|
|
|
const ProfilePicPlaceholder = (props) => {
|
2024-02-05 12:14:45 +05:00
|
|
|
const { colors } = useThemeColors();
|
|
|
|
|
return (
|
2024-02-29 23:26:58 +05:00
|
|
|
<TouchableOpacity
|
2024-02-05 12:14:45 +05:00
|
|
|
style={{
|
|
|
|
|
alignItems: "center"
|
|
|
|
|
}}
|
2024-02-29 23:26:58 +05:00
|
|
|
activeOpacity={0.9}
|
2024-03-26 08:57:04 +05:00
|
|
|
onPress={props?.onChangePicture}
|
2024-02-05 12:14:45 +05:00
|
|
|
>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: colors.primary.shade,
|
|
|
|
|
borderRadius: 100,
|
2024-02-29 23:26:58 +05:00
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2024-02-05 12:14:45 +05:00
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center"
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-29 23:26:58 +05:00
|
|
|
<Icon size={50} color={colors.primary.accent} name="account-outline" />
|
2024-02-05 12:14:45 +05:00
|
|
|
</View>
|
2024-02-29 23:26:58 +05:00
|
|
|
</TouchableOpacity>
|
2024-02-05 12:14:45 +05:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-26 08:57:04 +05:00
|
|
|
const onChangePicture = () => {
|
|
|
|
|
const theme =
|
|
|
|
|
useThemeStore.getState().colorScheme === "dark"
|
|
|
|
|
? useThemeStore.getState().darkTheme
|
|
|
|
|
: useThemeStore.getState().lightTheme;
|
|
|
|
|
|
|
|
|
|
ImagePicker.openPicker({
|
|
|
|
|
compressImageMaxWidth: 256,
|
|
|
|
|
compressImageMaxHeight: 256,
|
|
|
|
|
compressImageQuality: 0.8,
|
|
|
|
|
avoidEmptySpaceAroundImage: true,
|
|
|
|
|
cropping: true,
|
|
|
|
|
cropperCircleOverlay: true,
|
|
|
|
|
mediaType: "photo",
|
|
|
|
|
forceJpg: true,
|
|
|
|
|
includeBase64: true,
|
|
|
|
|
writeTempFile: false,
|
|
|
|
|
cropperToolbarColor: theme.scopes.base.primary.background,
|
|
|
|
|
cropperToolbarTitle: "Edit profile picture",
|
|
|
|
|
cropperActiveWidgetColor: theme.scopes.base.primary.accent,
|
|
|
|
|
cropperToolbarWidgetColor: theme.scopes.base.primary.icon
|
|
|
|
|
}).then(async (image) => {
|
|
|
|
|
if (!image.data) return;
|
|
|
|
|
await db.settings.setProfile({
|
|
|
|
|
profilePicture: "data:image/jpeg;base64," + image.data
|
|
|
|
|
});
|
|
|
|
|
useUserStore.setState({
|
|
|
|
|
profile: db.settings.getProfile()
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-07 04:20:13 +05:00
|
|
|
const SettingsUserSection = ({ item }) => {
|
2023-08-01 12:07:21 +05:00
|
|
|
const { colors } = useThemeColors();
|
2024-04-25 15:29:42 +05:00
|
|
|
const [user, premium] = useUserStore((state) => [state.user, state.premium]);
|
2022-08-26 16:19:39 +05:00
|
|
|
const lastSynced = useUserStore((state) => state.lastSynced);
|
2024-02-05 12:14:45 +05:00
|
|
|
const lastSyncStatus = useUserStore((state) => state.lastSyncStatus);
|
|
|
|
|
const { isInternetReachable } = useNetInfo();
|
|
|
|
|
const isOffline = !isInternetReachable;
|
2024-02-29 23:26:58 +05:00
|
|
|
const userProfile = useUserStore((state) => state.profile);
|
2022-04-07 04:20:13 +05:00
|
|
|
|
2021-11-24 09:57:23 +05:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{user ? (
|
|
|
|
|
<>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: 12,
|
2024-02-05 12:14:45 +05:00
|
|
|
paddingTop: 50,
|
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
|
paddingBottom: 20,
|
2024-04-18 15:18:00 +05:00
|
|
|
borderColor: colors.primary.border
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-11-24 09:57:23 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2024-02-05 12:14:45 +05:00
|
|
|
flexDirection: "row",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
width: "100%"
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-11-24 09:57:23 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2024-02-05 12:14:45 +05:00
|
|
|
flexDirection: "column",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
width: "100%"
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-11-24 09:57:23 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2024-02-05 12:14:45 +05:00
|
|
|
borderWidth: 2,
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
marginBottom: 10,
|
|
|
|
|
borderColor: colors.primary.accent
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-29 23:26:58 +05:00
|
|
|
{userProfile?.profilePicture ? (
|
2024-03-26 08:57:04 +05:00
|
|
|
<TouchableOpacity
|
|
|
|
|
onPress={onChangePicture}
|
|
|
|
|
activeOpacity={1}
|
|
|
|
|
>
|
|
|
|
|
<Image
|
|
|
|
|
source={{
|
|
|
|
|
uri: userProfile?.profilePicture
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
|
|
|
|
borderRadius: 100
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</TouchableOpacity>
|
2024-02-29 23:26:58 +05:00
|
|
|
) : (
|
2024-03-26 08:57:04 +05:00
|
|
|
<ProfilePicPlaceholder onChangePicture={onChangePicture} />
|
2024-02-29 23:26:58 +05:00
|
|
|
)}
|
2024-02-05 12:14:45 +05:00
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
alignItems: "center"
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2024-04-25 15:29:42 +05:00
|
|
|
{premium ? (
|
|
|
|
|
<Heading color={colors.primary.accent} size={SIZE.sm}>
|
|
|
|
|
{SUBSCRIPTION_STATUS_STRINGS[
|
|
|
|
|
user.subscription?.type
|
2024-07-27 10:19:43 +05:00
|
|
|
]?.toUpperCase() || strings.basic()}
|
2024-04-25 15:29:42 +05:00
|
|
|
</Heading>
|
|
|
|
|
) : null}
|
2024-02-05 12:14:45 +05:00
|
|
|
|
2024-02-29 23:26:58 +05:00
|
|
|
<Paragraph
|
|
|
|
|
onPress={() => {
|
|
|
|
|
presentDialog({
|
2024-04-25 15:29:42 +05:00
|
|
|
title: "Set your full name",
|
|
|
|
|
paragraph:
|
|
|
|
|
"Your name is end-to-end encrypted and only visible to you.",
|
2024-02-29 23:26:58 +05:00
|
|
|
positiveText: "Save",
|
|
|
|
|
input: true,
|
|
|
|
|
inputPlaceholder: "Enter your full name",
|
|
|
|
|
defaultValue: userProfile?.fullName,
|
|
|
|
|
positivePress: async (value) => {
|
2024-03-22 08:34:25 +05:00
|
|
|
db.settings
|
2024-02-29 23:26:58 +05:00
|
|
|
.setProfile({
|
|
|
|
|
fullName: value
|
|
|
|
|
})
|
|
|
|
|
.then(async () => {
|
|
|
|
|
useUserStore.setState({
|
2024-03-22 08:34:25 +05:00
|
|
|
profile: db.settings.getProfile()
|
2024-02-29 23:26:58 +05:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
color={colors.primary.heading}
|
|
|
|
|
size={SIZE.lg}
|
|
|
|
|
>
|
|
|
|
|
{userProfile?.fullName
|
|
|
|
|
? userProfile.fullName + " "
|
2024-07-27 10:19:43 +05:00
|
|
|
: strings.setYourName() + " "}
|
2024-02-29 23:26:58 +05:00
|
|
|
<AppIcon name="pencil" size={SIZE.lg} />
|
2024-02-05 12:14:45 +05:00
|
|
|
</Paragraph>
|
|
|
|
|
|
|
|
|
|
<Paragraph color={colors.primary.heading} size={SIZE.xs}>
|
|
|
|
|
{user?.email}
|
|
|
|
|
</Paragraph>
|
|
|
|
|
|
|
|
|
|
<Paragraph
|
2021-11-24 09:57:23 +05:00
|
|
|
style={{
|
2024-02-29 23:26:58 +05:00
|
|
|
flexWrap: "wrap",
|
|
|
|
|
marginTop: 5
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
2024-02-05 12:14:45 +05:00
|
|
|
size={SIZE.xs}
|
|
|
|
|
color={colors.secondary.heading}
|
2022-01-22 12:57:05 +05:00
|
|
|
>
|
2024-02-05 12:14:45 +05:00
|
|
|
{!user ? (
|
2024-07-27 10:19:43 +05:00
|
|
|
strings.notLoggedIn()
|
2024-02-05 12:14:45 +05:00
|
|
|
) : lastSynced && lastSynced !== "Never" ? (
|
|
|
|
|
<>
|
|
|
|
|
{lastSyncStatus === SyncStatus.Failed
|
2024-07-27 10:19:43 +05:00
|
|
|
? strings.syncFailed()
|
|
|
|
|
: strings.synced()}{" "}
|
2022-04-07 04:20:13 +05:00
|
|
|
<TimeSince
|
2024-02-05 12:14:45 +05:00
|
|
|
style={{
|
|
|
|
|
fontSize: SIZE.xs,
|
|
|
|
|
color: colors.secondary.paragraph
|
|
|
|
|
}}
|
2022-04-07 04:20:13 +05:00
|
|
|
time={lastSynced}
|
|
|
|
|
/>
|
2024-07-27 10:19:43 +05:00
|
|
|
{isOffline ? ` (${strings.offline()})` : ""}
|
2024-02-05 12:14:45 +05:00
|
|
|
</>
|
|
|
|
|
) : (
|
2024-07-27 10:19:43 +05:00
|
|
|
strings.never()
|
2024-02-05 12:14:45 +05:00
|
|
|
)}{" "}
|
|
|
|
|
<Icon
|
|
|
|
|
name="checkbox-blank-circle"
|
|
|
|
|
size={11}
|
|
|
|
|
allowFontScaling
|
|
|
|
|
color={
|
|
|
|
|
!user || lastSyncStatus === SyncStatus.Failed
|
|
|
|
|
? colors.error.icon
|
|
|
|
|
: isOffline
|
|
|
|
|
? colors.static.orange
|
|
|
|
|
: colors.success.icon
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</Paragraph>
|
2021-11-24 09:57:23 +05:00
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
|
2022-08-26 16:19:39 +05:00
|
|
|
{item.sections.map((item) => (
|
2022-04-07 04:20:13 +05:00
|
|
|
<SectionItem key={item.name} item={item} />
|
|
|
|
|
))}
|
2021-11-24 09:57:23 +05:00
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SettingsUserSection;
|