common: fix ts errors

This commit is contained in:
ammarahm-ed
2023-08-26 20:10:34 +05:00
committed by Abdullah Atta
parent 843be2a62c
commit 9ef40c01ce
4 changed files with 16 additions and 12 deletions

View File

@@ -17,8 +17,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
import Database from "@notesnook/core/dist/api/index"; import Database from "@notesnook/core/dist/api/index";
export const database = new Database(); export const database = new Database();

View File

@@ -17,24 +17,29 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { formatDate } from "@notesnook/core/dist/utils/date"; import {
FormatDateOptions,
TimeFormat,
formatDate
} from "@notesnook/core/dist/utils/date";
import { database } from "../database"; import { database } from "../database";
import { formatReminderTime } from "@notesnook/core/dist/collections/reminders"; import { formatReminderTime } from "@notesnook/core/dist/collections/reminders";
import { Reminder } from "@notesnook/core/dist/types";
export function getFormattedDate( export function getFormattedDate(
date: string | number | Date, date: string | number | Date,
type: "time" | "date-time" | "date" = "date-time" type: FormatDateOptions["type"]
) { ) {
return formatDate(date, { return formatDate(date, {
dateFormat: database.settings?.getDateFormat() as string, dateFormat: database.settings?.getDateFormat() as string,
timeFormat: database.settings?.getTimeFormat() as string, timeFormat: database.settings?.getTimeFormat() as string,
type: type type: type
}); } as FormatDateOptions);
} }
export function getFormattedReminderTime(reminder: any, short = false) { export function getFormattedReminderTime(reminder: Reminder, short = false) {
return formatReminderTime(reminder, short, { return formatReminderTime(reminder, short, {
dateFormat: database.settings?.getDateFormat() as string, dateFormat: database.settings?.getDateFormat() as string,
timeFormat: database.settings?.getTimeFormat() as string timeFormat: database.settings?.getTimeFormat() as TimeFormat
}); });
} }

View File

@@ -16,9 +16,10 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Item } from "@notesnook/core/dist/types";
import { database } from "../database"; import { database } from "../database";
export function getTotalNotes(item?: any) { export function getTotalNotes(item?: Item) {
if (!item || (item.type !== "notebook" && item.type !== "topic")) return 0; if (!item || (item.type !== "notebook" && item.type !== "topic")) return 0;
if (item.type === "topic") { if (item.type === "topic") {
return ( return (

View File

@@ -64,20 +64,20 @@ export function getTimeFormat(format: TimeFormat) {
return format === "12-hour" ? "hh:mm A" : "HH:mm"; return format === "12-hour" ? "hh:mm A" : "HH:mm";
} }
type TimeOptions = { export type TimeOptions = {
type: "time"; type: "time";
timeFormat: TimeFormat; timeFormat: TimeFormat;
}; };
type DateOptions = { export type DateOptions = {
type: "date"; type: "date";
dateFormat: string; dateFormat: string;
}; };
type DateTimeOptions = { export type DateTimeOptions = {
type: "date-time"; type: "date-time";
dateFormat: string; dateFormat: string;
timeFormat: TimeFormat; timeFormat: TimeFormat;
}; };
type FormatDateOptions = TimeOptions | DateOptions | DateTimeOptions; export type FormatDateOptions = TimeOptions | DateOptions | DateTimeOptions;
export function formatDate( export function formatDate(
date: string | number | Date | null | undefined, date: string | number | Date | null | undefined,