@dative-gpi/foundation-shared-services 0.0.50 → 0.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { computed, ref, watch } from "vue";
1
+ import { computed, ref } from "vue";
2
2
 
3
- const languageCode = ref<string | null>(null);
3
+ const languageCode = ref<string | undefined>(undefined);
4
4
 
5
5
  export const useAppLanguageCode = () => {
6
6
  const setLanguageCode = (payload: string) => {
@@ -73,25 +73,32 @@ export const useAppTimeZone = () => {
73
73
  return today.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
74
74
  }
75
75
 
76
- const pickerToEpoch = (value: Date): number => {
77
- // FSCalendar is always in machine time zone, so we need to convert it to user time zone
78
- return value.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
76
+ const pickerToEpoch = (value: Date | null | undefined): number => {
77
+ if (value != null) {
78
+ // FSCalendar is always in machine time zone, so we need to convert it to user time zone
79
+ return value.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
80
+ }
81
+ return 0;
79
82
  };
80
83
 
81
- const epochToPicker = (value: number): Date => {
82
- // Epoch is always without time zone, so we need to convert it to user time zone
84
+ const epochToPicker = (value: number | null | undefined): Date => {
83
85
  const date = new Date(0);
84
- date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
86
+ if (value != null) {
87
+ // Epoch is always without time zone, so we need to convert it to user time zone
88
+ date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
89
+ }
85
90
  return date;
86
91
  };
87
92
 
88
93
  const epochToPickerHeader = (value: number): { d: number, m: number, y: number } => {
89
94
  const date = new Date(0);
90
- date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
95
+ if (value != null) {
96
+ date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
97
+ }
91
98
  return { d: date.getDate(), m: date.getMonth(), y: date.getFullYear() };
92
99
  };
93
100
 
94
- const epochToLongDateFormat = (value: number): string => {
101
+ const epochToLongDateFormat = (value: number | null | undefined): string => {
95
102
  if (value == null || !isFinite(value)) {
96
103
  return "";
97
104
  }
@@ -100,7 +107,7 @@ export const useAppTimeZone = () => {
100
107
  return format(date, "EEEE dd LLLL yyyy", { locale: getLocale() });
101
108
  };
102
109
 
103
- const epochToLongTimeFormat = (value: number): string => {
110
+ const epochToLongTimeFormat = (value: number | null | undefined): string => {
104
111
  if (value == null || !isFinite(value)) {
105
112
  return "";
106
113
  }
@@ -109,7 +116,7 @@ export const useAppTimeZone = () => {
109
116
  return format(date, overrideFormat(date, "EEEE dd LLLL yyyy HH:mm"), { locale: getLocale() })
110
117
  };
111
118
 
112
- const epochToShortDateFormat = (value: number): string => {
119
+ const epochToShortDateFormat = (value: number | null | undefined): string => {
113
120
  if (value == null || !isFinite(value)) {
114
121
  return "";
115
122
  }
@@ -125,7 +132,7 @@ export const useAppTimeZone = () => {
125
132
  }
126
133
  };
127
134
 
128
- const epochToShortTimeFormat = (value: number): string => {
135
+ const epochToShortTimeFormat = (value: number | null | undefined): string => {
129
136
  if (value == null || !isFinite(value)) {
130
137
  return "";
131
138
  }
@@ -1,4 +1,5 @@
1
1
  export * from "./services";
2
2
  export * from "./app";
3
3
 
4
+ export * from "./useFiles";
4
5
  export * from "./useFoundationShared";
@@ -0,0 +1,25 @@
1
+ import { FILE_URL } from "../config/urls";
2
+
3
+ export const useFiles = () => {
4
+ const downloadFile = (id: string): void => {
5
+ window.open(FILE_URL(id), "_blank");
6
+ };
7
+
8
+ const readFile = (file: File): Promise<string | ArrayBuffer | null> => {
9
+ return new Promise((resolve, reject) => {
10
+ const reader = new FileReader();
11
+ reader.addEventListener("load", (fileEv) => {
12
+ resolve(fileEv.target && fileEv.target.result);
13
+ });
14
+ reader.addEventListener("error", (fileEv) => {
15
+ reject(fileEv);
16
+ });
17
+ reader.readAsDataURL(file);
18
+ });
19
+ };
20
+
21
+ return {
22
+ downloadFile,
23
+ readFile
24
+ };
25
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-services",
3
3
  "sideEffects": false,
4
- "version": "0.0.50",
4
+ "version": "0.0.52",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -11,10 +11,10 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "@dative-gpi/bones-ui": "^0.0.61",
14
- "@dative-gpi/foundation-shared-domain": "0.0.50",
14
+ "@dative-gpi/foundation-shared-domain": "0.0.52",
15
15
  "@microsoft/signalr": "^8.0.0",
16
16
  "vue": "^3.2.0",
17
17
  "vue-router": "^4.2.5"
18
18
  },
19
- "gitHead": "be18a14ae47c91c1f3ccd22a196593050f06aae8"
19
+ "gitHead": "1cea46f60262aceae3135923684ed4a5af60d0bb"
20
20
  }