mobile: formatted dates in editor

This commit is contained in:
ammarahm-ed
2023-06-05 15:08:40 +05:00
committed by Abdullah Atta
parent 3b6a2cb9de
commit 1521a7d120
7 changed files with 32 additions and 4 deletions

View File

@@ -50,6 +50,8 @@ export type Settings = {
corsProxy: string;
fontSize: string;
fontFamily: string;
dateFormat: string;
timeFormat: string;
};
export type EditorProps = {

View File

@@ -130,6 +130,11 @@ export const useEditorEvents = (
const deviceMode = useSettingStore((state) => state.deviceMode);
const fullscreen = useSettingStore((state) => state.fullscreen);
const corsProxy = useSettingStore((state) => state.settings.corsProxy);
const [dateFormat, timeFormat] = useSettingStore((state) => [
state.dateFormat,
state.timeFormat
]);
const handleBack = useRef<NativeEventSubscription>();
const readonly = useEditorStore((state) => state.readonly);
const isPremium = useUserStore((state) => state.premium);
@@ -173,7 +178,9 @@ export const useEditorEvents = (
doubleSpacedLines: doubleSpacedLines,
corsProxy: corsProxy,
fontSize: defaultFontSize,
fontFamily: defaultFontFamily
fontFamily: defaultFontFamily,
dateFormat: db.settings?.getDateFormat(),
timeFormat: db.settings?.getTimeFormat()
});
}, [
fullscreen,
@@ -190,7 +197,9 @@ export const useEditorEvents = (
noToolbar,
corsProxy,
defaultFontSize,
defaultFontFamily
defaultFontFamily,
dateFormat,
timeFormat
]);
const onBackPress = useCallback(async () => {

View File

@@ -28,6 +28,7 @@ import Paragraph from "../../components/ui/typography/paragraph";
import { useThemeStore } from "../../stores/use-theme-store";
import { SIZE } from "../../utils/size";
import { DATE_FORMATS, TIME_FORMATS } from "@notesnook/core/common";
import { useSettingStore } from "../../stores/use-setting-store";
export const DateFormatSelector = () => {
const colors = useThemeStore((state) => state.colors);
@@ -38,6 +39,9 @@ export const DateFormatSelector = () => {
menuRef.current?.hide();
db.settings.setDateFormat(item);
setDateFormat(item);
useSettingStore.setState({
dateFormat: item
});
};
return (
@@ -116,6 +120,9 @@ export const TimeFormatSelector = () => {
menuRef.current?.hide();
db.settings.setTimeFormat(item);
setTimeFormat(item);
useSettingStore.setState({
timeFormat: item
});
};
const TimeFormats = {

View File

@@ -106,6 +106,8 @@ export interface SettingStore extends State {
setRequestBiometrics: (requestBiometrics: boolean) => void;
insets: Insets;
setInsets: (insets: Insets) => void;
timeFormat: string;
dateFormat: string;
}
const { width, height } = Dimensions.get("window");
@@ -170,6 +172,8 @@ export const useSettingStore = create<SettingStore>((set) => ({
requestBiometrics: false,
setRequestBiometrics: (requestBiometrics) => set({ requestBiometrics }),
setInsets: (insets) => set({ insets }),
timeFormat: "12-hour",
dateFormat: "DD-MM-YYYY",
insets: initialWindowMetrics?.insets
? initialWindowMetrics.insets
: { top: 0, right: 0, left: 0, bottom: 0 }

View File

@@ -110,7 +110,9 @@ const Tiptap = ({
},
downloadOptions: {
corsHost: settings.corsProxy
}
},
dateFormat: settings.dateFormat,
timeFormat: settings.timeFormat as "12-hour" | "24-hour" | undefined
},
[layout, settings.readonly, tick, settings.doubleSpacedLines]
);

View File

@@ -32,7 +32,9 @@ const initialState = {
readonly: globalThis.readonly,
doubleSpacedLines: true,
fontFamily: "sans-serif",
fontSize: "16px"
fontSize: "16px",
timeFormat: "12-hour",
dateFormat: "DD-MM-YYYY"
};
global.settingsController = {

View File

@@ -41,6 +41,8 @@ export type Settings = {
corsProxy: string;
fontSize: number;
fontFamily: string;
timeFormat: string;
dateFormat: string;
};
/* eslint-disable no-var */