esoftplay 0.0.114 → 0.0.115

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.
Binary file
package/bin/build.js CHANGED
@@ -228,8 +228,7 @@ yarn-error.log\n\
228
228
  import * as ErrorReport from 'esoftplay/error';
229
229
  import * as Notifications from 'expo-notifications';
230
230
  import React, { useEffect, useRef } from 'react';
231
- import { GestureHandlerRootView } from 'react-native-gesture-handler';
232
- import { enableScreens, enableFreeze } from 'react-native-screens';
231
+ import { enableFreeze, enableScreens } from 'react-native-screens';
233
232
  const { globalIdx } = require('esoftplay/global');
234
233
  enableScreens();
235
234
  enableFreeze();
@@ -244,11 +243,7 @@ export default function App() {
244
243
  ErrorReport.getError()
245
244
  }, [])
246
245
 
247
- return (
248
- <GestureHandlerRootView style={{ flex: 1 }}>
249
- <Home />
250
- </GestureHandlerRootView>
251
- )
246
+ return (<Home />)
252
247
  }`;
253
248
  let expoLib = [
254
249
  '@expo/vector-icons',
package/bin/cli.js CHANGED
@@ -211,7 +211,7 @@ function createMaster(module_name) {
211
211
  } else {
212
212
  throw "Mohon install esoftplay package terlebih dahulu"
213
213
  }
214
-
214
+
215
215
  function injectConfig(configPath) {
216
216
  if (fs.existsSync(configPath)) {
217
217
  const exsConf = require(configPath)
@@ -220,12 +220,12 @@ function createMaster(module_name) {
220
220
  fs.writeFileSync(configPath, JSON.stringify({..._cf}, undefined, 2))
221
221
  }
222
222
  }
223
-
223
+
224
224
  /* injectConfig */
225
225
  injectConfig("../../config.json")
226
226
  injectConfig("../../config.live.json")
227
227
  injectConfig("../../config.debug.json")
228
-
228
+
229
229
  /* move assets */
230
230
  if (fs.existsSync("./assets/")) {
231
231
  if (!fs.existsSync("../../assets/" + moduleName))
@@ -234,7 +234,7 @@ function createMaster(module_name) {
234
234
  shell("cp -r -n ./assets/* ../../assets/" + moduleName + "/")
235
235
  } catch (error) { }
236
236
  }
237
-
237
+
238
238
  if (fs.existsSync("./fonts/")) {
239
239
  if (!fs.existsSync("../../" + assetsFonts))
240
240
  shell("mkdir -p ../../" + assetsFonts)
@@ -242,18 +242,18 @@ function createMaster(module_name) {
242
242
  shell("cp -r -n ./fonts/* ../../" + assetsFonts + "/")
243
243
  } catch (error) { }
244
244
  }
245
-
245
+
246
246
  /* inject lang */
247
247
  if (fs.existsSync("./id.json")) {
248
248
  let moduleLang = require("./id.json")
249
249
  if (fs.existsSync("../../assets/locale/id.json")) {
250
250
  let projectLang = require("../../assets/locale/id.json")
251
- let _lg = merge(moduleLang, projectLang)
251
+ let _lg = merge(moduleLang, projectLang)
252
252
  moduleLang = {..._lg}
253
253
  }
254
254
  fs.writeFileSync("../../assets/locale/id.json", JSON.stringify(moduleLang, undefined, 2))
255
255
  }
256
-
256
+
257
257
  /* inject libs */
258
258
  if (fs.existsSync("./libs.json")) {
259
259
  let libs = require("./libs.json")
@@ -300,33 +300,33 @@ function createMaster(module_name) {
300
300
  const shell = require('child_process').execSync;
301
301
  const assetsModule = "assets/" + moduleName
302
302
  const assetsFonts = "assets/fonts"
303
-
303
+
304
304
  /* copy module */
305
305
  if (fs.existsSync("./" + moduleName))
306
306
  shell("rm -r ./" + moduleName)
307
307
  shell("cp -r ../mobile/modules/" + moduleName + " ./")
308
-
308
+
309
309
  /* copy assets */
310
310
  if (fs.existsSync("./assets"))
311
311
  shell("rm -r ./assets")
312
312
  shell("mkdir -p assets")
313
- if (fs.existsSync('../mobile/' + assetsModule + '/*'))
314
- shell("cp -r ../mobile/" + assetsModule + "/* ./assets/")
315
-
313
+ if (fs.existsSync('../mobile/' + assetsModule + '/'))
314
+ shell("cp -r ../mobile/" + assetsModule + "/ ./assets/")
315
+
316
316
  /* copy fonts */
317
317
  if (fs.existsSync("./fonts"))
318
318
  shell("rm -r ./fonts")
319
319
  shell("mkdir -p fonts")
320
- if (fs.existsSync('../mobile/' + assetsFonts + '/*'))
321
- shell("cp -r ../mobile/" + assetsFonts + "/* ./assets/")
322
-
320
+ if (fs.existsSync('../mobile/' + assetsFonts + '/'))
321
+ shell("cp -r ../mobile/" + assetsFonts + "/* ./fonts/")
322
+
323
323
  /* copy lang */
324
324
  if (fs.existsSync("../mobile/assets/locale/id.json")) {
325
325
  if (fs.existsSync("./id.json"))
326
326
  shell("rm ./id.json")
327
327
  shell("cp ../mobile/assets/locale/id.json .")
328
328
  }
329
-
329
+
330
330
  /* copy config */
331
331
  if (fs.existsSync("../mobile/config.json")) {
332
332
  const confMobile = require("../mobile/config.json")
@@ -334,8 +334,14 @@ function createMaster(module_name) {
334
334
  const confMaster = { [moduleName]: confMobile.config[moduleName] }
335
335
  fs.writeFileSync("./config.json", JSON.stringify(confMaster, undefined, 2))
336
336
  }
337
+ /* copy config font */
338
+ if (confMobile.config.hasOwnProperty("fonts")) {
339
+ const config = require("./config.json")
340
+ const confMaster = { ['fonts']: confMobile.config['fonts'] }
341
+ fs.writeFileSync("./config.json", JSON.stringify(Object.assign(config, confMaster), undefined, 2))
342
+ }
337
343
  }
338
-
344
+
339
345
  if (fs.existsSync("./package.json")) {
340
346
  const packJson = require("./package.json")
341
347
  const letterVersion = "abcdefghijklmnopqrstuvwxyz"
@@ -357,7 +363,7 @@ function createMaster(module_name) {
357
363
  nextNumber = Number(nextNumber) + 1
358
364
  nextVersion += nextNumber
359
365
  }
360
-
366
+
361
367
  const newPackJson = { ...packJson, version: nextVersion }
362
368
  fs.writeFileSync("./package.json", JSON.stringify(newPackJson, undefined, 2))
363
369
  shell("npm publish")
@@ -368,7 +374,8 @@ function createMaster(module_name) {
368
374
  fs.mkdirSync(PATH + "master/assets")
369
375
  fs.mkdirSync(PATH + "master/" + module_name)
370
376
  fs.writeFileSync(PATH + "master/index.js", index)
371
- fs.writeFileSync(PATH + "master/libs.js", libs)
377
+ fs.writeFileSync(PATH + "master/config.json", `{}`)
378
+ fs.writeFileSync(PATH + "master/libs.json", libs)
372
379
  fs.writeFileSync(PATH + "master/mover.js", mover)
373
380
  fs.writeFileSync(PATH + "master/package.json", packjson)
374
381
  fs.writeFileSync(PATH + "master/publisher.js", publisher)
package/bin/router.js CHANGED
@@ -55,6 +55,7 @@ var SuffixHooksProperty = ('Property').trim()
55
55
  var Persistor = {};
56
56
  var Extender = {};
57
57
  var NavsExclude = {};
58
+ var NavsOrientation = {};
58
59
  var grabClass = null;
59
60
  var delReducer = true;
60
61
  var countLoop = 0; // jumlah file yang telah dihitung
@@ -74,6 +75,7 @@ const Stack = createNativeStackNavigator();
74
75
  export default function m(props): any{
75
76
  const { user, initialState, handler } = props
76
77
  const econf = esp.config()
78
+ const appOrientation = econf?.orientation ? String(econf.orientation) : 'portrait'
77
79
  return(
78
80
  <NavigationContainer
79
81
  ref={(r) => LibNavigation.setRef(r)}
@@ -83,7 +85,7 @@ export default function m(props): any{
83
85
  <Stack.Navigator
84
86
  headerMode="none"
85
87
  initialRouteName={(user?.id || user?.user_id) ? econf.home.member : econf.home.public}
86
- screenOptions={{ headerShown: false, contentStyle: { backgroundColor: 'white' }, stackAnimation: 'default', stackPresentation: 'push' }}>
88
+ screenOptions={{ orientation: appOrientation, headerShown: false, contentStyle: { backgroundColor: 'white' }, stackAnimation: 'default', stackPresentation: 'push' }}>
87
89
  `+ navs + `
88
90
  </Stack.Navigator>
89
91
  </NavigationContainer>
@@ -127,11 +129,14 @@ checks.forEach(modules => {
127
129
  var isHooks = false
128
130
  var isUseLibs = false
129
131
  /* REGEX HOOKS */
130
- if (n = (/\n?(?:(?:\/\/\s{0,})|(?:\/\*\s{0,}))noPage/).exec(data)) {
132
+ if ((/\n?(?:(?:\/\/\s{0,})|(?:\/\*\s{0,}))noPage/).exec(data)) {
131
133
  NavsExclude[module + '/' + file.slice(0, file.lastIndexOf('.'))] = true
132
134
  } else {
133
135
  NavsExclude[module + '/' + file.slice(0, file.lastIndexOf('.'))] = false
134
136
  }
137
+ if (m = (/\n?(?:(?:\/\/\s{0,})|(?:\/\*\s{0,}))orientation:([a-zAZ_]+)/).exec(data)) {
138
+ NavsOrientation[module + '/' + file.slice(0, file.lastIndexOf('.'))] = m?.[1]
139
+ }
135
140
  if (isIndexed) {
136
141
  if (n = (/\n?(?:(?:\/\/\s{0,})|(?:\/\*\s{0,}))useLibs/).exec(data)) {
137
142
  isUseLibs = true
@@ -401,6 +406,25 @@ declare module "esoftplay" {
401
406
  function home(): any;
402
407
  function log(message?: any, ...optionalParams: any[]): void;
403
408
  function routes(): any;
409
+ const logColor : {
410
+ reset: string,
411
+ black: string,
412
+ red: string,
413
+ green: string,
414
+ yellow: string,
415
+ blue: string,
416
+ magenta: string,
417
+ cyan: string,
418
+ white: string,
419
+ backgroundBlack: string,
420
+ backgroundRed: string,
421
+ backgroundGreen: string,
422
+ backgroundYellow: string,
423
+ backgroundBlue: string,
424
+ backgroundMagenta: string,
425
+ backgroundCyan: string,
426
+ backgroundWhite: string,
427
+ }
404
428
  }
405
429
  interface useGlobalReturn<T> {
406
430
  useState: () => [T, (newState: T | ((a:T) => T)) => T | undefined, () => void],
@@ -627,10 +651,14 @@ function createRouter() {
627
651
  let importer = []
628
652
  let screens = []
629
653
  Navigations.forEach((nav) => {
654
+ const orientation = NavsOrientation[nav]
630
655
  const [module, task] = nav.split('/')
631
656
  const comp = ucword(module) + ucword(task)
632
657
  importer.push(comp)
633
- screens.push("\t\t\t\t<Stack.Screen name={\"" + nav + "\"} component={" + comp + "} />")
658
+ if (orientation)
659
+ screens.push("\t\t\t\t<Stack.Screen name={\"" + nav + "\"} options={{ orientation: '" + orientation + "' }} component={" + comp + "} />")
660
+ else
661
+ screens.push("\t\t\t\t<Stack.Screen name={\"" + nav + "\"} component={" + comp + "} />")
634
662
  })
635
663
 
636
664
  let N = Nav5(importer.join(", "), screens.join("\n"))
package/error.ts CHANGED
@@ -30,17 +30,19 @@ export function setError(error?: any) {
30
30
  }
31
31
 
32
32
  export function reportApiError(fetch: any, error: any) {
33
-
33
+ let routes = UserRoutes.state().get()
34
+ let lastIndex = routes?.routes?.length - 1 ?? 0
34
35
  const user = UserClass.state().get()
35
36
  let config = esp.config()
36
37
  let msg = [
37
38
  'slug: ' + "#" + manifest?.slug,
38
- 'dev: ' + Platform.OS + ' - ' + Constants.deviceName,
39
+ 'error: ' + error,
40
+ '\n\n\ndev: ' + Platform.OS + ' - ' + Constants.deviceName,
39
41
  'app/pub_id: ' + Constants.appOwnership + '/' + (config?.publish_id || '-'),
40
42
  'user_id: ' + user?.id || user?.user_id || '-',
41
43
  'username: ' + user?.username || '-',
44
+ 'module:' + routes?.routes?.[lastIndex]?.name,
42
45
  'fetch: ' + String(JSON.stringify(fetch || {}, undefined, 2)).replace(/[\[\]\{\}\"]+/g, ''),
43
- 'error: ' + error
44
46
  ].join('\n')
45
47
 
46
48
  if (manifest?.packagerOpts) {
@@ -67,7 +69,8 @@ export function getError() {
67
69
  let _e = JSON.parse(e)
68
70
  let msg = [
69
71
  'slug: ' + "#" + manifest?.slug,
70
- 'name: ' + manifest?.name + ' - sdk' + pack?.dependencies?.expo,
72
+ 'error: \n' + _e.error,
73
+ '\n\nname: ' + manifest?.name + ' - sdk' + pack?.dependencies?.expo,
71
74
  'domain: ' + config.domain + config.uri,
72
75
  'package: ' + (Platform.OS == 'ios' ? manifest?.ios?.bundleIdentifier : manifest?.android?.package) + ' - v' + (Platform.OS == 'ios' ? app.expo.ios.buildNumber : app.expo.android.versionCode),
73
76
  'device: ' + Platform.OS + ' | ' + Constants.deviceName,
@@ -75,11 +78,12 @@ export function getError() {
75
78
  'user_id: ' + _e?.user?.id || _e?.user?.user_id || '-',
76
79
  'username: ' + _e?.user?.username || '-',
77
80
  'module: ' + _e.routes,
78
- 'error: \n' + _e.error,
79
81
  ].join('\n')
80
82
  // config?.errorReport?.telegramIds?.forEach?.((id: string) => {
81
83
  if (msg.includes(`Invariant Violation: "main" has not been registered. This can happen if`)) {
82
84
  // remove error that unsolved
85
+ } else if (msg.includes(`deleteAdsCache`)) {
86
+ // remove error that unsolved
83
87
  } else {
84
88
  let post = {
85
89
  text: msg,
package/esp.ts CHANGED
@@ -13,13 +13,14 @@ const ignoreWarns = [
13
13
  "AsyncStorage has been extracted from react-native",
14
14
  "EventEmitter.removeListener",
15
15
  "Got a component with the name 'm'",
16
- "Did not receive response to shouldStartLoad in time,"
16
+ "Did not receive response to shouldStartLoad in time",
17
+ "startLoadWithResult invoked with invalid lockldentifier",
17
18
  ];
18
19
 
19
20
  const err = console.error;
20
21
  console.error = (...arg) => {
21
22
  for (let i = 0; i < ignoreWarns.length; i++) {
22
- if (arg[0].startsWith(ignoreWarns[i])) return;
23
+ if (arg[0].startsWith(ignoreWarns[i])) return;
23
24
  }
24
25
  err(...arg);
25
26
  };
@@ -27,11 +28,14 @@ console.error = (...arg) => {
27
28
  const warn = console.warn;
28
29
  console.warn = (...arg) => {
29
30
  for (let i = 0; i < ignoreWarns.length; i++) {
30
- if (arg[0].startsWith(ignoreWarns[i])) return;
31
+ if (arg[0].startsWith(ignoreWarns[i])) return;
31
32
  }
32
33
  warn(...arg);
33
34
  };
34
35
  LogBox.ignoreLogs(ignoreWarns);
36
+
37
+
38
+
35
39
  let app = require('../../app.json');
36
40
  let conf = require('../../config.json');
37
41
  let lconf
@@ -200,10 +204,29 @@ export default (() => {
200
204
  }
201
205
  function log(message?: any, ...optionalParams: any[]) {
202
206
  if (config("isDebug") == 1) {
203
- console.log(message, ...optionalParams);
207
+ console.log(message, ...optionalParams, "\x1b[0m");
204
208
  }
205
209
  }
206
- return { appjson, log, home, isDebug, navigations, langId, lang, config, assets, routes, mod, versionName }
210
+ const logColor = {
211
+ reset: "\x1b[0m",
212
+ black: "\x1b[30m",
213
+ red: "\x1b[31m",
214
+ green: "\x1b[32m",
215
+ yellow: "\x1b[33m",
216
+ blue: "\x1b[34m",
217
+ magenta: "\x1b[35m",
218
+ cyan: "\x1b[36m",
219
+ white: "\x1b[37m",
220
+ backgroundBlack: "\x1b[40m",
221
+ backgroundRed: "\x1b[41m",
222
+ backgroundGreen: "\x1b[42m",
223
+ backgroundYellow: "\x1b[43m",
224
+ backgroundBlue: "\x1b[44m",
225
+ backgroundMagenta: "\x1b[45m",
226
+ backgroundCyan: "\x1b[46m",
227
+ backgroundWhite: "\x1b[47m",
228
+ }
229
+ return { appjson, log, home, isDebug, navigations, langId, lang, config, assets, routes, mod, versionName, logColor }
207
230
  })()
208
231
 
209
232
  // var a = esp.assets("bacground") // mengambil file dari folder images
package/global.ts CHANGED
@@ -103,7 +103,7 @@ const n = () => {
103
103
  }
104
104
 
105
105
  function subscribe(func: any) {
106
- R.useEffect(() => {
106
+ R.useLayoutEffect(() => {
107
107
  subscriber[_idx].push(func);
108
108
  return () => {
109
109
  subscriber[_idx] = fastFilter(subscriber?.[_idx], (f) => f !== func)
@@ -1,6 +1,5 @@
1
- import { esp, LibCrypt, LibNet_status, LibObject, LibProgress, LibToastProperty, LibUtils, LogStateProperty } from 'esoftplay';
1
+ import { esp, LibCrypt, LibNet_status, LibProgress, LibToastProperty, LibUtils, LogStateProperty } from 'esoftplay';
2
2
  import { reportApiError } from "esoftplay/error";
3
- import moment from "esoftplay/moment";
4
3
  import Constants from 'expo-constants';
5
4
 
6
5
  const { manifest } = Constants;
@@ -9,7 +8,7 @@ export default class ecurl {
9
8
  controller = new AbortController()
10
9
  signal = this.controller.signal
11
10
  timeout = 30000;
12
- maxRetry = 2;
11
+ maxRetry = 3;
13
12
  timeoutContext: any = null;
14
13
  isDebug = esp.config("isDebug");
15
14
  post: any;
@@ -46,7 +45,6 @@ export default class ecurl {
46
45
  this.withHeader = this.withHeader.bind(this);
47
46
  this.initTimeout = this.initTimeout.bind(this);
48
47
  this.cancelTimeout = this.cancelTimeout.bind(this);
49
- // this.createApiTesterUris = this.createApiTesterUris.bind(this)
50
48
  const str: any = LibNet_status.state().get();
51
49
  if (uri && str.isOnline) {
52
50
  this.init(uri, post, onDone, onFailed, debug);
@@ -88,35 +86,6 @@ export default class ecurl {
88
86
  this.uri = uri
89
87
  }
90
88
 
91
- // createApiTesterUris(): void {
92
-
93
- // if (esp.isDebug('onlyAvailableOnDebug')) {
94
- // setTimeout(() => {
95
- // const options = this.fetchConf.options
96
- // const msg = this.uri.replace('/', '.').split('?')[0] + `
97
- // /* RARE USAGE : to simulate LibCurl().secure() : default false */
98
- // const IS_SECURE_POST = `+ this.isSecure + `
99
-
100
- // const EXTRACT = []
101
- // const EXTRACT_CHECK = []
102
-
103
- // const GET = {`+ JSON.stringify(LibUtils.getUrlParams(options?.url) || '') + `
104
- // }
105
-
106
- // const POST = {`+ options._post + `
107
- // }
108
- // module.exports = { POST, GET, IS_SECURE_POST, EXTRACT, EXTRACT_CHECK }
109
- // `
110
- // let post = {
111
- // text: msg,
112
- // chat_id: '-626800023',
113
- // disable_web_page_preview: true
114
- // }
115
- // this.custom('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
116
- // }, 1000);
117
- // }
118
- // }
119
-
120
89
  protected setApiKey(apiKey: string): void {
121
90
  this.apiKey = apiKey
122
91
  }
@@ -132,7 +101,6 @@ export default class ecurl {
132
101
 
133
102
  protected closeConnection(): void {
134
103
  this.controller?.abort?.()
135
- // this?.abort?.cancel('Oops, Sepertinya ada gangguan jaringan... Silahkan coba beberapa saat lagi');
136
104
  }
137
105
 
138
106
  protected onDone(result: any, msg?: string): void {
@@ -192,9 +160,8 @@ export default class ecurl {
192
160
  }).catch((r) => {
193
161
  this.cancelTimeout()
194
162
  LibProgress.hide()
163
+ LibToastProperty.show('Koneksi internet kamu tidak stabil, silahkan coba beberapa saat lagi')
195
164
  this.onFetchFailed(r)
196
- // if (onFailed)
197
- // onFailed(r, true)
198
165
  })
199
166
  }
200
167
  }
@@ -266,7 +233,6 @@ export default class ecurl {
266
233
  payload = this.encodeGetValue(_uri.includes('?') ? _uri.substring(_uri.indexOf('?') + 1, _uri.length) : '');
267
234
  _uri = _uri.includes('?') ? _uri.substring(0, _uri.indexOf('?')) : _uri;
268
235
  }
269
- // console.log("HASH", method, _uri, payload, typeof payload == 'string' ? this.urlEncode(payload) : payload)
270
236
  signature = method + ':' + _uri + ':' + LibUtils.shorten(typeof payload == 'string' ? this.urlEncode(payload) : payload);
271
237
  }
272
238
  return signature
@@ -315,18 +281,6 @@ export default class ecurl {
315
281
  if (onDone) onDone(resJson, false)
316
282
  this.onDone(resJson)
317
283
  } else {
318
- // Alert.alert(this.alertTimeout.title, this.alertTimeout.message, [
319
- // {
320
- // text: this.alertTimeout.ok,
321
- // style: 'cancel',
322
- // onPress: () => this.custom(uri, post, onDone, debug)
323
- // },
324
- // {
325
- // text: this.alertTimeout.cancel,
326
- // style: 'destructive',
327
- // onPress: () => { }
328
- // }
329
- // ])
330
284
  this.onFetchFailed(resText)
331
285
  LibProgress.hide()
332
286
  this.onError(resText)
@@ -334,21 +288,7 @@ export default class ecurl {
334
288
  }).catch((e) => {
335
289
  this.cancelTimeout()
336
290
  LibProgress.hide()
337
- // Alert.alert(this.alertTimeout.title, this.alertTimeout.message, [
338
- // {
339
- // text: this.alertTimeout.ok,
340
- // style: 'cancel',
341
- // onPress: () => this.custom(uri, post, onDone, debug)
342
- // },
343
- // {
344
- // text: this.alertTimeout.cancel,
345
- // style: 'destructive',
346
- // onPress: () => { }
347
- // }
348
- // ])
349
291
  this.onFetchFailed(e)
350
- // if (onDone)
351
- // onDone(e, true)
352
292
  })
353
293
  }
354
294
  }
@@ -396,107 +336,31 @@ export default class ecurl {
396
336
  _post: post
397
337
  }
398
338
 
399
-
400
- if (manifest?.packagerOpts?.dev && LogStateProperty) {
401
- const allData = LogStateProperty.state().get() || []
402
- const logEnable = LogStateProperty.enableLog().get()
403
- let uriOrigin = this.uri
404
- if (this.uri == '' && this.url != '') {
405
- uriOrigin = this.url.replace(/(https?:\/\/)/g, '')
406
- let uriArray = uriOrigin.split('/')
407
- let domain = uriArray[0]
408
- if (!domain.startsWith('api.')) {
409
- uriOrigin = ''
410
- } else {
411
- let uri = uriArray.slice(1, uriArray.length - 1).join('/')
412
- let get = uriArray[uriArray.length - 1];
413
- let newGet = '';
414
- if (get && get.includes('?')) {
415
- let rebuildGet = get.split('?')
416
- for (let i = 0; i < rebuildGet.length; i++) {
417
- const element = rebuildGet[i];
418
- if (!element.includes('=')) {
419
- newGet += '?id=' + element
420
- } else {
421
- newGet += (newGet.includes('?') ? '&' : '?') + element
422
- }
423
- }
424
- } else {
425
- newGet = get;
426
- }
427
- uriOrigin = uri + newGet
428
- }
429
- }
430
- const complete_uri = uriOrigin
431
- const _uri = complete_uri.includes('?') ? complete_uri.split('?')[0] : complete_uri
432
- const _get = complete_uri.includes('?') ? complete_uri.split('?')[1].split('&').map((x: any) => x.split('=')).map((t: any) => {
433
- return ({ [t[0]]: [t[1]] })
434
- }) : []
435
- const get = Object.assign({}, ..._get)
436
- const _post = post && Object.keys(post).map((key) => {
437
- return ({ [key]: [decodeURI(post[key])] })
438
- }) || []
439
- const postNew = Object.assign({}, ..._post)
440
-
441
- if (_uri != '') {
442
- const data = {
443
- [_uri]: {
444
- secure: this.isSecure,
445
- time: moment().format('YYYY-MM-DD HH:mm:ss'),
446
- get: get,
447
- post: postNew,
448
- }
449
- }
450
- let dt = LibObject.unshift(allData, data)()
451
- if (logEnable) {
452
- LogStateProperty.state().set(dt)
453
- }
454
- }
339
+ //api_logger
340
+ if (LogStateProperty) {
341
+ LogStateProperty.doLogCurl(this.uri, this.url, post, this.isSecure)
455
342
  }
456
343
 
457
344
  this.initTimeout(upload ? 120000 : this.timeout)
458
345
  if (debug == 1) esp.log(this.url + this.uri, options)
459
346
  this.fetchConf = { url: this.url + this.uri, options: options }
460
347
 
461
- // if (Platform.OS == 'android' && Platform.Version <= 22) {
462
- // var res = await fetch(this.url + this.uri, options);
463
- // let resText = await res.text()
464
- // this.onFetched(resText, onDone, onFailed, debug)
465
- // } else
466
- // if (!upload) {
467
- // LibWorker.curl(this.url + this.uri, options, async (resText) => {
468
- // if (typeof resText == 'string') {
469
- // this.onFetched(resText, onDone, onFailed, debug)
470
- // }
471
- // })
472
- // } else {
473
348
  fetch(this.url + this.uri, options).then(async (res) => {
474
349
  this.cancelTimeout()
475
350
  let resText = await res.text()
476
351
  this.onFetched(resText, onDone, onFailed, debug)
477
352
  }).catch((r) => {
478
- // Alert.alert(this.alertTimeout.title, this.alertTimeout.message, [
479
- // {
480
- // text: this.alertTimeout.ok,
481
- // style: 'cancel',
482
- // onPress: () => this.init(uri, post, onDone, onFailed, debug)
483
- // },
484
- // {
485
- // text: this.alertTimeout.cancel,
486
- // style: 'destructive',
487
- // onPress: () => { }
488
- // }
489
- // ])
490
353
  if (this.maxRetry > 0) {
491
- this.init(uri, post, onDone, onFailed, debug)
492
- this.maxRetry = this.maxRetry - 1
354
+ setTimeout(() => {
355
+ this.init(uri, post, onDone, onFailed, debug)
356
+ this.maxRetry = this.maxRetry - 1
357
+ }, 100);
493
358
  } else {
494
- LibToastProperty.show("Koneksi internet anda tidak stabil, silahkan coba beberapa saat lagi")
359
+ LibToastProperty.show("Koneksi internet kamu tidak stabil, silahkan coba beberapa saat lagi")
495
360
  }
496
361
  this.onFetchFailed(r)
497
362
  LibProgress.hide()
498
363
  })
499
- // }
500
364
  }
501
365
 
502
366
 
@@ -534,7 +398,7 @@ export default class ecurl {
534
398
  out = 'Terjadi kesalahan, biar ' + esp.appjson()?.expo?.name + ' bereskan, silahkan coba beberapa saat lagi atau kembali ke halaman utama'
535
399
  }
536
400
  if (ltext.includes('timeout exceeded')) {
537
- out = 'Koneksi internet anda tidak stabil, silahkan coba beberapa saat lagi'
401
+ out = 'Koneksi internet kamu tidak stabil, silahkan coba beberapa saat lagi'
538
402
  }
539
403
  }
540
404
  return out
@@ -543,9 +407,6 @@ export default class ecurl {
543
407
  private onError(msg: string): void {
544
408
  esp.log("\x1b[31m", msg)
545
409
  esp.log("\x1b[0m")
546
- // if (esp.isDebug('') && msg == '') {
547
- // return
548
- // }
549
410
  delete this.fetchConf.options.cancelToken
550
411
  reportApiError(this.fetchConf, msg)
551
412
  LibProgress.hide()
@@ -0,0 +1,29 @@
1
+ // withHooks
2
+
3
+ import { LibPicture } from 'esoftplay';
4
+ import { Image, ImageStyle, View } from 'react-native';
5
+ export interface LibImage_shadowArgs {
6
+
7
+ }
8
+ export interface LibImage_shadowProps {
9
+ style: ImageStyle,
10
+ source: any,
11
+ shadowRadius?: number,
12
+ blurRadius?: number
13
+ }
14
+ export default function m(props: LibImage_shadowProps): any {
15
+ let { height, width }: any = props.style
16
+ if (!height || !width) throw new Error("width and height is required")
17
+
18
+ const extra_height = (props.shadowRadius || 0.15) * (Number(height) || 1)
19
+
20
+ return (
21
+ <View style={{ ...props.style, height: Number(height) + extra_height, width, backgroundColor: 'orange' }} >
22
+ <Image source={props.source} blurRadius={props.blurRadius || 8} style={{ height, width, ...props.style, marginTop: extra_height }} />
23
+ <View style={{ position: 'absolute', bottom: 0, left: 0, right: 0, height: 0.55 * width, width }} >
24
+ <LibPicture source={require('../../assets/blur.png')} style={{ width: '100%', height: '100%' }} />
25
+ </View>
26
+ <LibPicture source={props.source} style={{ height, width, ...props.style, position: 'absolute' }} />
27
+ </View>
28
+ )
29
+ }
@@ -1,6 +1,8 @@
1
+ import { useGlobalReturn } from 'esoftplay';
1
2
  // noPage
2
3
 
3
- import { esp, LibCrypt, LibCurl, LibNavigation, UserClass, UserNotification, _global } from "esoftplay";
4
+ import { esp, LibCrypt, LibCurl, LibNavigation, LibObject, useGlobalState, UserClass, UserNotification, _global } from "esoftplay";
5
+ import { fastFilter } from "esoftplay/fast";
4
6
  import Constants from 'expo-constants';
5
7
  import * as Notifications from 'expo-notifications';
6
8
  import { Alert, Linking, Platform } from "react-native";
@@ -28,7 +30,6 @@ import moment from '../../moment';
28
30
 
29
31
  Notifications.setNotificationHandler({
30
32
  handleNotification: async (notif) => {
31
- UserNotification.user_notification_loadData();
32
33
  return ({
33
34
  shouldShowAlert: true,
34
35
  shouldPlaySound: true,
@@ -38,10 +39,151 @@ Notifications.setNotificationHandler({
38
39
  },
39
40
  });
40
41
 
42
+ const lastUrlState = useGlobalState<any>(undefined)
43
+
44
+ function mainUrl(): string {
45
+ const { protocol, domain, uri } = esp.config()
46
+ return protocol + "://" + domain + uri;
47
+ }
48
+
49
+ function readAll(ids: (string | number)[]) {
50
+ let url = mainUrl() + "user/push-read";
51
+ const { salt } = esp.config()
52
+ let post: any = {
53
+ notif_id: ids.join(','),
54
+ user_id: "",
55
+ secretkey: new LibCrypt().encode(salt + "|" + moment().format("YYYY-MM-DD hh:mm:ss"))
56
+ }
57
+ new LibCurl(url, post)
58
+ }
59
+
60
+ function splitArray(array: any[], maxLength: number): any[] {
61
+ const parts = maxLength // items per chunk
62
+ const splitedArray = array.reduce((resultArray: any, item, index) => {
63
+ const chunkIndex = Math.floor(index / parts)
64
+ if (!resultArray[chunkIndex]) {
65
+ resultArray[chunkIndex] = [] // start a new chunk
66
+ }
67
+ resultArray[chunkIndex].push(item)
68
+ return resultArray
69
+ }, [])
70
+ return splitedArray
71
+ }
72
+
41
73
  export default class m {
42
74
 
75
+ static state(): useGlobalReturn<any> {
76
+ return lastUrlState
77
+ }
78
+
79
+ static loadData(isFirst?: boolean): void {
80
+ // console.log('LOADDATA', isFirst)
81
+ let _uri = mainUrl() + "user/push-notif/desc"
82
+ const lastUrl = lastUrlState.get()
83
+ if (lastUrl == -1) {
84
+ return
85
+ }
86
+ if (lastUrl && !isFirst) {
87
+ _uri = lastUrl
88
+ }
89
+ const user = UserClass.state().get()
90
+ if (!user?.id) {
91
+ Notifications.setBadgeCountAsync(0)
92
+ }
93
+ const { salt } = esp.config()
94
+ let post: any = {
95
+ user_id: "",
96
+ secretkey: new LibCrypt().encode(salt + "|" + moment().format("YYYY-MM-DD hh:mm:ss"))
97
+ }
98
+ if (user) {
99
+ post["user_id"] = user.id || user.user_id
100
+ post["group_id"] = user.group_id || esp.config('group_id')
101
+ }
102
+
103
+ // console.log(esp.logColor.cyan, 'curl: ' + _uri, esp.logColor.reset)
104
+ new LibCurl(_uri, post,
105
+ (res: any) => {
106
+ // console.log(esp.logColor.green, 'next: ' + res.next, '\n length: ' + res?.list?.length, res.list[0].message, esp.logColor.reset)
107
+ if (res?.list?.length > 0) {
108
+ const urls: string[] = UserNotification.state().get().urls
109
+ // console.log(urls)
110
+ if (urls && urls.indexOf(_uri) < 0) {
111
+ let { data, unread } = UserNotification.state().get()
112
+ // console.log(nUnread+" => nUnread")
113
+ let nUnread
114
+ if (isFirst) {
115
+ nUnread = fastFilter(res.list, (row) => row.status != 2).length
116
+ UserNotification.state().set({
117
+ data: res.list,
118
+ urls: [],
119
+ unread: nUnread
120
+ })
121
+ } else {
122
+ nUnread = unread + fastFilter(res.list, (row) => row.status != 2).length
123
+ data.push(...res.list)
124
+ UserNotification.state().set({
125
+ data: data,
126
+ urls: [_uri, ...urls],
127
+ unread: nUnread
128
+ })
129
+ }
130
+ Notifications.setBadgeCountAsync(nUnread)
131
+ }
132
+ }
133
+ if (res.next) {
134
+ lastUrlState.set(res.next)
135
+ } else {
136
+ lastUrlState.set(-1)
137
+ }
138
+ }, (msg) => {
139
+
140
+ }
141
+ )
142
+ }
143
+
144
+ static add(id: number, user_id: number, group_id: number, title: string, message: string, params: string, status: 0 | 1 | 2, created?: string, updated?: string): void {
145
+ const item = { id, user_id, group_id, title, message, params, status, created, updated }
146
+ let data = UserNotification.state().get().data
147
+ data.unshift(item)
148
+ UserNotification.state().set({
149
+ ...UserNotification.state().get(),
150
+ data: data
151
+ })
152
+ }
153
+
154
+ static drop(): void {
155
+ UserNotification.state().reset()
156
+ }
157
+
158
+ static markRead(id?: string | number, ..._ids: (string | number)[]): void {
159
+ // console.log("markRead")
160
+ let { data, unread, urls } = UserNotification.state().get()
161
+ let nUnread = unread > 0 ? unread - 1 : 0
162
+ let ids = [id, ..._ids]
163
+ // console.log(ids)
164
+ ids.forEach((id) => {
165
+ const index = data.findIndex((row) => String(row.id) == String(id))
166
+ if (index > -1) {
167
+ data = LibObject.set(data, 2)(index, 'status')
168
+ nUnread = unread > 0 ? unread - 1 : 0
169
+ }
170
+ })
171
+ // console.log(JSON.stringify(data))
172
+ UserNotification.state().set({
173
+ urls,
174
+ data: data,
175
+ unread: nUnread
176
+ })
177
+ Notifications.setBadgeCountAsync(nUnread)
178
+ const idsToPush = splitArray(ids, 200)
179
+ idsToPush.forEach((ids) => {
180
+ readAll(ids)
181
+ })
182
+ }
183
+
184
+
43
185
  static onAction(notification: any): void {
44
- UserNotification.user_notification_loadData()
186
+ m.loadData(true)
45
187
  const data = m.getData(notification)
46
188
  function doOpen(data: any) {
47
189
  if (!_global.NavsIsReady) {
@@ -62,7 +204,7 @@ export default class m {
62
204
  return x?.notification?.request?.content?.data
63
205
  }
64
206
 
65
- static listen(dataRef: any): () => void {
207
+ static listen(dataRef: any): void {
66
208
  if (esp.config('notification') == 1) {
67
209
  if (Platform.OS == 'android')
68
210
  Notifications.setNotificationChannelAsync(
@@ -70,7 +212,7 @@ export default class m {
70
212
  {
71
213
  sound: 'default',
72
214
  enableLights: true,
73
- description: "this is description",
215
+ description: "Please enable notifications permissions",
74
216
  name: esp.appjson().expo.name,
75
217
  importance: Notifications.AndroidImportance.MAX,
76
218
  showBadge: true,
@@ -79,11 +221,8 @@ export default class m {
79
221
  }
80
222
  )
81
223
  UserClass.pushToken();
82
- dataRef.receive = Notifications.addNotificationReceivedListener((x) => {
83
- UserNotification.user_notification_loadData()
84
- })
224
+ dataRef.receive = Notifications.addNotificationReceivedListener(() => { })
85
225
  }
86
- else return () => { }
87
226
  }
88
227
 
89
228
  static requestPermission(callback?: (token: any) => void): Promise<any> {
@@ -130,18 +269,7 @@ export default class m {
130
269
  if (!data) return
131
270
  if (typeof data == 'string')
132
271
  data = JSON.parse(data)
133
- const crypt = new LibCrypt();
134
- const salt = esp.config("salt");
135
- const config = esp.config();
136
- let uri = config.protocol + "://" + config.domain + config.uri + "user/push-read"
137
- new LibCurl(uri, {
138
- notif_id: data.id,
139
- secretkey: crypt.encode(salt + "|" + moment().format("YYYY-MM-DD hh:mm:ss"))
140
- }, () => {
141
- UserNotification.user_notification_loadData();
142
- }, () => {
143
-
144
- })
272
+ m.markRead(data.id)
145
273
  let param = data;
146
274
  if (param.action)
147
275
  switch (param.action) {
@@ -175,17 +303,7 @@ export default class m {
175
303
  }
176
304
 
177
305
  static openNotif(data: any): void {
178
- const salt = esp.config("salt");
179
- const config = esp.config();
180
- let uri = config.protocol + "://" + config.domain + config.uri + "user/push-read"
181
- new LibCurl(uri, {
182
- notif_id: data.id,
183
- secretkey: new LibCrypt().encode(salt + "|" + moment().format("YYYY-MM-DD hh:mm:ss"))
184
- }, () => {
185
- UserNotification.user_notification_setRead(data.id)
186
- }, () => {
187
- // esp.log(msg)
188
- })
306
+ m.markRead(data.id)
189
307
  let param = JSON.parse(data.params)
190
308
  switch (param.action) {
191
309
  case "alert":
@@ -3,9 +3,9 @@
3
3
 
4
4
  import { esp, LibStyle, LibWorker, LibWorkloop, useSafeState } from 'esoftplay';
5
5
  import * as FileSystem from 'expo-file-system';
6
- import React, { useMemo } from 'react';
6
+ import { useLayoutEffect } from 'react';
7
7
  import { PixelRatio, Platform, View } from 'react-native';
8
- import FastImage from 'react-native-fast-image'
8
+ import FastImage from 'react-native-fast-image';
9
9
  const sh = require("shorthash")
10
10
 
11
11
  export interface LibPictureSource {
@@ -99,7 +99,7 @@ export default function m(props: LibPictureProps): any {
99
99
  else
100
100
  resizeMode = FastImage.resizeMode.cover
101
101
 
102
- if (props.source.hasOwnProperty("uri") && (!width || !height)) {
102
+ if (!width || !height) {
103
103
  if (width) {
104
104
  height = width
105
105
  } else {
@@ -108,7 +108,7 @@ export default function m(props: LibPictureProps): any {
108
108
  console.warn("Width and Height is Required");
109
109
  }
110
110
 
111
- useMemo(() => {
111
+ useLayoutEffect(() => {
112
112
  if (!valid || (Platform.OS == 'android' && Platform.Version <= 22)) {
113
113
  return
114
114
  }
@@ -1,6 +1,6 @@
1
1
  // noPage
2
2
 
3
- import { LibComponent } from 'esoftplay';
3
+ import { esp, LibComponent, LibNotification, UserClass } from 'esoftplay';
4
4
  import React from 'react';
5
5
  import { InteractionManager, View } from 'react-native';
6
6
  import { WebView } from 'react-native-webview';
@@ -73,6 +73,15 @@ export default (() => {
73
73
  })
74
74
  }
75
75
  }
76
+ componentDidMount(): void {
77
+ super.componentDidMount();
78
+ const user = UserClass.state().get()
79
+ if (user){
80
+ if(esp.config().notification == 1){
81
+ LibNotification.loadData(true)
82
+ }
83
+ }
84
+ }
76
85
 
77
86
  render(): any {
78
87
  return (
@@ -2,7 +2,7 @@
2
2
  // noPage
3
3
 
4
4
  import { useSafeState } from 'esoftplay';
5
- import { useEffect } from 'react';
5
+ import { useLayoutEffect } from 'react';
6
6
  import { fastFilter } from './../../fast';
7
7
 
8
8
  export default (() => {
@@ -20,7 +20,7 @@ export default (() => {
20
20
  });
21
21
  }
22
22
 
23
- useEffect(() => {
23
+ useLayoutEffect(() => {
24
24
  if (!dt['setter-' + formName]) {
25
25
  dt['setter-' + formName] = []
26
26
  }
@@ -1,13 +1,13 @@
1
1
  // withHooks
2
2
  // noPage
3
3
 
4
- import { esp, LibDialog, LibImage, LibNet_status, LibProgress, LibStyle, LibToast, LibUpdaterProperty, LibVersion, LibWorker, LibWorkloop, LibWorkview, UseDeeplink, UserClass, UserLoading, UserMain, UserRoutes, useSafeState, _global } from 'esoftplay';
4
+ import { ChattingFirebase, esp, LibDialog, LibImage, LibNet_status, LibProgress, LibStyle, LibToast, LibUpdaterProperty, LibVersion, LibWorker, LibWorkloop, LibWorkview, UseDeeplink, UserClass, UserLoading, UserMain, UserRoutes, useSafeState, _global } from 'esoftplay';
5
5
  import * as Font from "expo-font";
6
- import React, { useEffect } from "react";
6
+ import React, { useEffect, useLayoutEffect } from "react";
7
7
  import { View } from "react-native";
8
+ import { GestureHandlerRootView } from 'react-native-gesture-handler';
8
9
  import Navs from "../../cache/navs";
9
10
 
10
-
11
11
  export interface UserIndexProps {
12
12
 
13
13
  }
@@ -47,7 +47,7 @@ export default function m(props: UserIndexProps): any {
47
47
  UserRoutes.set(currentState)
48
48
  }
49
49
 
50
- useEffect(() => {
50
+ useLayoutEffect(() => {
51
51
  // const timeout = setTimeout(() => {
52
52
  // setLoading(false)
53
53
  // }, 15 * 1000);
@@ -58,23 +58,22 @@ export default function m(props: UserIndexProps): any {
58
58
  setLoading(false)
59
59
  }
60
60
  })()
61
-
61
+
62
62
  UserClass.isLogin(async () => {
63
63
  ready.current += 1
64
64
  if (ready.current >= 2) {
65
65
  setLoading(false)
66
66
  }
67
- LibUpdaterProperty.check((isNew) => { })
68
67
  })
69
68
  if (esp.config('firebase').hasOwnProperty('apiKey')) {
70
69
  try {
71
- const chatFirebase = require('../chatting/firebase')?.default
72
- if (chatFirebase)
73
- chatFirebase?.signInAnonymously?.();
70
+ if (ChattingFirebase)
71
+ ChattingFirebase?.signInAnonymously?.();
74
72
  } catch (error) {
75
73
 
76
74
  }
77
75
  }
76
+ LibUpdaterProperty.check((isNew) => { })
78
77
  }, [])
79
78
 
80
79
  useEffect(() => {
@@ -87,7 +86,7 @@ export default function m(props: UserIndexProps): any {
87
86
 
88
87
  if (loading) return <UserLoading />
89
88
  return (
90
- <>
89
+ <GestureHandlerRootView style={{ flex: 1 }}>
91
90
  <View style={{ flex: 1 }}>
92
91
  <LibWorker />
93
92
  <LibWorkview />
@@ -101,7 +100,7 @@ export default function m(props: UserIndexProps): any {
101
100
  <LibToast />
102
101
  </View>
103
102
  <View style={{ backgroundColor: LibStyle.colorNavigationBar || 'white', height: LibStyle.isIphoneX ? 35 : 0 }} />
104
- </>
103
+ </GestureHandlerRootView>
105
104
  )
106
105
  }
107
106
 
@@ -1,8 +1,7 @@
1
1
  // noPage
2
2
 
3
3
 
4
- import { LibComponent, LibStyle, UserNotification } from "esoftplay";
5
- import React from "react";
4
+ import { LibComponent, LibStyle } from "esoftplay";
6
5
  import { Text, TouchableOpacity, View } from "react-native";
7
6
 
8
7
  export interface UserNotifbadgeProps {
@@ -25,7 +24,6 @@ export default class Enotifbadge extends LibComponent<UserNotifbadgeProps, UserN
25
24
 
26
25
  componentDidMount(): void {
27
26
  super.componentDidMount()
28
- UserNotification.user_notification_loadData()
29
27
  }
30
28
 
31
29
  render(): any {
@@ -1,16 +1,8 @@
1
1
  //
2
2
 
3
- import {
4
- esp, LibComponent, LibCrypt,
5
- LibCurl, LibIcon, LibList, LibNotification, LibObject, LibStatusbar, LibStyle, LibUtils, useGlobalReturn, useGlobalState,
6
- UserClass, UserNotification_item
7
- } from "esoftplay";
8
- import * as Notifications from 'expo-notifications';
9
- import React from "react";
3
+ import { LibComponent, LibIcon, LibList, LibNotification, LibStatusbar, LibStyle, useGlobalReturn, useGlobalState, UserNotification_item } from "esoftplay";
10
4
  import { Pressable, Text, TouchableOpacity, View } from "react-native";
11
- import { fastFilter } from "../../fast";
12
5
  //@ts-ignore
13
- import moment from "../../moment";
14
6
  export interface UserNotificationProps {
15
7
  navigation: any,
16
8
  data: any[]
@@ -26,109 +18,13 @@ const initState = {
26
18
  unread: 0
27
19
  };
28
20
 
29
- const state = useGlobalState(initState, { persistKey: 'user_notification', isUserData: true })
30
-
21
+ const state = useGlobalState<any>(initState, { persistKey: "user_notification_data", isUserData: true })
31
22
  class m extends LibComponent<UserNotificationProps, UserNotificationState> {
32
23
 
33
24
  static state(): useGlobalReturn<any> {
34
25
  return state
35
26
  }
36
27
 
37
- static add(id: number, user_id: number, group_id: number, title: string, message: string, params: string, status: 0 | 1 | 2, created?: string, updated?: string): void {
38
- const item = { id, user_id, group_id, title, message, params, status, created, updated }
39
- let data = state.get().data
40
- data.unshift(item)
41
- state.set({
42
- ...state.get(),
43
- data: data
44
- })
45
- }
46
-
47
- static drop(): void {
48
- state.set(initState)
49
- }
50
-
51
- static user_notification_loadData(): void {
52
- const { protocol, domain, uri, salt } = esp.config()
53
- let _uri = protocol + "://" + domain + uri + "user/push-notif"
54
- let data = state.get().data
55
- const user = UserClass.state().get()
56
- if (!user?.id) {
57
- Notifications.setBadgeCountAsync(0)
58
- }
59
- /* hapus yang lebih lama dari 3 bulan */
60
- const d = new Date();
61
- d.setMonth(d.getMonth() - 3);
62
- const created = LibUtils.moment(String(d.getDate())).format('YYYY-MM-DD HH:mm:ss')
63
- let cdata = fastFilter(data, (row) => row.created > created)
64
- if (cdata.length != data.length) {
65
- /* jika data tidak sama artinya ada yang expired > 3 bulan */
66
- state.set(LibObject.set(state.get(), cdata)('data'))
67
- }
68
- if (data && data.length > 0) {
69
- const lastData = data[0]
70
- if (lastData.id)
71
- _uri += "?last_id=" + lastData.id || 0
72
- }
73
- let post: any = {
74
- user_id: "",
75
- secretkey: new LibCrypt().encode(salt + "|" + moment().format("YYYY-MM-DD hh:mm:ss"))
76
- }
77
- if (user) {
78
- post["user_id"] = user.id || user.user_id
79
- post["group_id"] = user.group_id || esp.config('group_id')
80
- }
81
- m.user_notification_fetchData(_uri, post);
82
- }
83
-
84
- static user_notification_fetchData(uri: string, post: any): void {
85
- new LibCurl(uri, post,
86
- (res: any) => {
87
- m.user_notification_parseData(res.list, uri)
88
- if (res.next != "") {
89
- m.user_notification_fetchData(res.next, post)
90
- }
91
- }, (msg) => {
92
- }
93
- )
94
- }
95
-
96
- static user_notification_parseData(res: any[], uri: string): void {
97
- if (res.length > 0) {
98
- const urls = state.get().urls
99
- if (urls && urls.indexOf(uri) < 0) {
100
- let { data, urls, unread } = state.get()
101
- const nUnread = unread + fastFilter(res, (row) => row.status != 2).length
102
- state.set({
103
- data: [...res.reverse(), ...data],
104
- urls: [uri, ...urls],
105
- unread: nUnread
106
- })
107
- Notifications.setBadgeCountAsync(nUnread)
108
- }
109
- }
110
- }
111
-
112
- static user_notification_setRead(id: string | number): void {
113
- let { data, unread, urls } = state.get()
114
- const index = data.findIndex((row) => row.id == String(id))
115
- if (index > -1) {
116
- const nUnread = unread > 0 ? unread - 1 : 0
117
- state.set({
118
- urls,
119
- data: LibObject.set(data, 2)(index, 'status'),
120
- unread: nUnread
121
- })
122
- Notifications.setBadgeCountAsync(nUnread)
123
- }
124
- }
125
-
126
- componentDidMount(): void {
127
- super.componentDidMount()
128
- moment().locale(esp.langId());
129
- m.user_notification_loadData()
130
- }
131
-
132
28
  render(): any {
133
29
  const { colorPrimary, colorAccent, STATUSBAR_HEIGHT } = LibStyle;
134
30
  const { goBack } = this.props.navigation
@@ -152,7 +48,7 @@ class m extends LibComponent<UserNotificationProps, UserNotificationState> {
152
48
  </View>
153
49
  <LibList
154
50
  data={data}
155
- onRefresh={() => m.user_notification_loadData()}
51
+ onRefresh={() => LibNotification.loadData(true)}
156
52
  renderItem={(item: any) => (
157
53
  <TouchableOpacity onPress={() => LibNotification.openNotif(item)} >
158
54
  <UserNotification_item {...item} />
@@ -1,11 +1,10 @@
1
1
  // noPage
2
2
 
3
3
  import { LibStyle, LibUtils } from 'esoftplay';
4
- import React from 'react';
5
4
  import { Text, View } from 'react-native';
6
5
 
7
6
 
8
- export interface UserNotificationProps {
7
+ export interface UserNotification_itemProps {
9
8
  created: string,
10
9
  id: number,
11
10
  message: string,
@@ -17,7 +16,7 @@ export interface UserNotificationProps {
17
16
  updated: string,
18
17
  user_id: number,
19
18
  }
20
- export default function m(props: UserNotificationProps): any {
19
+ export default function m(props: UserNotification_itemProps): any {
21
20
  return (
22
21
  <View style={[{ padding: 16, flexDirection: "row", backgroundColor: "white", marginBottom: 3, marginHorizontal: 0, width: LibStyle.width }, LibStyle.elevation(1.5)]} >
23
22
  <View style={{}} >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.114",
3
+ "version": "0.0.115",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",
package/persist.ts CHANGED
@@ -1,29 +1,30 @@
1
- import AsyncStorage from '@react-native-async-storage/async-storage'
2
- import { useEffect, useMemo, useRef, useState } from 'react'
3
- import { fastFilter, fastLoop } from './fast'
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ import { useLayoutEffect, useMemo, useRef, useState } from 'react';
3
+ import { fastFilter, fastLoop } from './fast';
4
4
 
5
5
  export default (() => {
6
6
  let obj: any = {}
7
7
  let setter = {}
8
8
  return (key: string, def?: any): any[] => {
9
9
  const r = useRef(true)
10
- const [a, b] = useState(def)
10
+ const [state, setState] = useState(def)
11
11
 
12
12
  useMemo(() => { if (!setter[key]) setter[key] = [] }, [])
13
13
 
14
- function c(value: any) {
14
+ function set(value: any) {
15
15
  if (r.current) {
16
16
  if (value != undefined)
17
17
  AsyncStorage.setItem(key, JSON.stringify(value));
18
18
  else
19
- d()
19
+ del()
20
20
  fastLoop(setter[key], (cc) => cc(value))
21
21
  }
22
22
  }
23
23
 
24
- function e(callback?: (a?: typeof def) => void) {
24
+ function updater(callback?: (a?: typeof def) => void) {
25
25
  if (obj[key]) {
26
26
  clearTimeout(obj[key])
27
+ delete obj[key]
27
28
  }
28
29
  obj[key] = setTimeout(() => {
29
30
  if (r.current)
@@ -32,28 +33,28 @@ export default (() => {
32
33
  if (x) {
33
34
  const xx = JSON.parse(x)
34
35
  if (callback) callback(xx)
35
- c(xx)
36
+ set(xx)
36
37
  } else {
37
38
  if (callback) callback(def)
38
- c(def)
39
+ set(def)
39
40
  }
40
41
  })
41
42
  }, 100);
42
43
  }
43
44
 
44
- function d() {
45
+ function del() {
45
46
  AsyncStorage.removeItem(key)
46
47
  }
47
48
 
48
- useEffect(() => {
49
- setter[key].push(b)
50
- e()
49
+ useLayoutEffect(() => {
50
+ setter[key].push(setState)
51
+ updater()
51
52
  return () => {
52
53
  r.current = false
53
- setter[key] = fastFilter(setter[key], (x) => x !== b);
54
+ setter[key] = fastFilter(setter[key], (x) => x !== setState);
54
55
  }
55
56
  }, [])
56
57
 
57
- return [a, c, e, d]
58
+ return [state, set, updater, del]
58
59
  }
59
60
  })()