commit a76c174a82647e62577387baf9b17be44bd9f793
parent 04bd0ad095b5291d2da043cd9d3c1717fd88853b
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Fri, 23 Aug 2024 13:18:40 +0000
client: add capacitor date-picker api
Diffstat:
4 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/client/package.json b/client/package.json
@@ -16,6 +16,7 @@
"@capacitor/network": "^6.0.0",
"@capacitor/preferences": "^6.0.0",
"@capacitor/share": "^6.0.0",
+ "@radroots/capacitor-date-picker": "workspace:*",
"@radroots/capacitor-secure-storage": "workspace:*",
"@radroots/capacitor-wifi": "workspace:*"
},
diff --git a/client/src/capacitor/date-picker.ts b/client/src/capacitor/date-picker.ts
@@ -0,0 +1,16 @@
+import { DatePicker } from '@radroots/capacitor-date-picker';
+import type { IClientDatePicker, IClientDatePickerPresent } from '../types';
+
+export class CapacitorClientDatePicker implements IClientDatePicker {
+ public async present(opts: IClientDatePickerPresent): Promise<string | undefined> {
+ try {
+ const res = await DatePicker.present({
+ mode: opts.mode,
+ ios: {
+ style: "wheels",
+ },
+ });
+ if (typeof res.value === `string`) return res.value;
+ } catch (e) { };
+ };
+}
diff --git a/client/src/capacitor/index.ts b/client/src/capacitor/index.ts
@@ -1,8 +1,9 @@
import { Capacitor } from "@capacitor/core";
-import type { IClient, IClientBrowser, IClientDevice, IClientDialog, IClientHaptics, IClientKeystore, IClientNetwork, IClientPlatform, IClientPreferences, IClientShare, IClientWifi } from "../types";
+import type { IClient, IClientBrowser, IClientDatePicker, IClientDevice, IClientDialog, IClientHaptics, IClientKeystore, IClientNetwork, IClientPlatform, IClientPreferences, IClientShare, IClientWifi } from "../types";
import { parse_platform } from "../utils";
import { CapacitorClientBrowser } from "./browser";
+import { CapacitorClientDatePicker } from "./date-picker";
import { CapacitorClientDevice } from "./device";
import { CapacitorClientDialog } from "./dialog";
import { CapacitorClientHaptics } from "./haptics";
@@ -23,6 +24,7 @@ export class ClientCapacitor implements IClient {
private _wifi: IClientWifi = new CapacitorClientWifi();
private _dialog: IClientDialog = new CapacitorClientDialog();
private _browser: IClientBrowser = new CapacitorClientBrowser();
+ private _dates: IClientDatePicker = new CapacitorClientDatePicker();
public get platform() {
return this._platform;
@@ -63,4 +65,8 @@ export class ClientCapacitor implements IClient {
public get browser() {
return this._browser;
}
+
+ public get dates() {
+ return this._dates;
+ }
};
\ No newline at end of file
diff --git a/client/src/types.ts b/client/src/types.ts
@@ -12,6 +12,7 @@ export type IClient = {
wifi: IClientWifi;
dialog: IClientDialog;
browser: IClientBrowser;
+ dates: IClientDatePicker;
};
export type IClientPlatform = `androiď` | `ios` | `web`;
@@ -101,3 +102,12 @@ export type IClientBrowser = {
open(url: string): Promise<void>;
};
+export type IClientDatePickerPresentDatesMode = `date` | `time` | `dateAndTime`;
+
+export type IClientDatePickerPresent = {
+ mode: IClientDatePickerPresentDatesMode;
+};
+
+export type IClientDatePicker = {
+ present(opts: IClientDatePickerPresent): Promise<string | undefined>;
+};