@ledvance/base 1.1.39 → 1.1.40

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.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/base",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.39",
7
+ "version": "1.1.40",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.8.6",
@@ -11,16 +11,17 @@ interface Prop {
11
11
  colorAlpha: number
12
12
  enable: boolean
13
13
  setEnable: any
14
+ showSwitch?:boolean
14
15
  }
15
16
 
16
17
  const LdvSwitch = (props: Prop) => {
17
- const {title, color, colorAlpha, enable, setEnable} = props
18
+ const {title, color, colorAlpha, enable, setEnable, showSwitch = true} = props
18
19
  return (
19
20
  <View style={styles.titleBGView}>
20
21
  <Text style={styles.title}>{title}</Text>
21
22
  <View style={[styles.colorBlock, {backgroundColor: color, opacity: colorAlpha}]}/>
22
23
  <Spacer style={{flex: 1}} height={0} width={0}/>
23
- <SwitchButton value={enable} onValueChange={setEnable}/>
24
+ {showSwitch && <SwitchButton value={enable} onValueChange={setEnable}/>}
24
25
  </View>
25
26
  )
26
27
  }
@@ -0,0 +1,62 @@
1
+ import dayjs from 'dayjs';
2
+ export function findConflicts(schedule, object) {
3
+ const conflicts: any = [];
4
+ schedule.forEach(item => {
5
+ item.weeks = getLoopsForTheOnceItem(item);
6
+ });
7
+ object.weeks = getLoopsForTheOnceItem(object);
8
+ const objectStart = object.isSleep
9
+ ? object.time[0] * 60 + object.time[1]
10
+ : object.time[0] * 60 + object.time[1] - object.fade;
11
+ const objectEnd = object.isSleep
12
+ ? objectStart + object.fade
13
+ : object.time[0] * 60 + object.time[1];
14
+ for (let i = 0; i < schedule.length; i++) {
15
+ const { enable, weeks, time, fade, isSleep } = schedule[i];
16
+ if (enable === 0) continue;
17
+
18
+ const start = isSleep ? time[0] * 60 + time[1] : time[0] * 60 + time[1] - fade;
19
+ const end = isSleep ? start + fade : time[0] * 60 + time[1];
20
+
21
+ let conflict = false;
22
+ for (let j = 0; j < 7; j++) {
23
+ if (weeks[j] && start < 0 && object.weeks[j - 1 < 0 ? 6 : j - 1]) {
24
+ if (objectEnd - 24 * 60 > start) {
25
+ conflict = true;
26
+ break;
27
+ }
28
+ }
29
+ if (object.weeks[j] && weeks[j]) {
30
+ if (objectStart < end && objectEnd > start) {
31
+ conflict = true;
32
+ break;
33
+ }
34
+ }
35
+ if (weeks[j] && end > 24 * 60 && object.weeks[j + 1 > 6 ? 0 : j + 1]) {
36
+ if (end - 24 * 60 > objectStart) {
37
+ conflict = true;
38
+ break;
39
+ }
40
+ }
41
+ }
42
+
43
+ if (conflict) {
44
+ conflicts.push(schedule[i]);
45
+ }
46
+ }
47
+
48
+ return conflicts;
49
+ }
50
+ // once
51
+ function isLoopsEqualToOnce(loops) {
52
+ return loops.every(item => item === 0 || item === '0');
53
+ }
54
+
55
+ function getLoopsForTheOnceItem(item) {
56
+ let newLoops = [...item.loops];
57
+ if (isLoopsEqualToOnce(newLoops)) {
58
+ const now = dayjs();
59
+ newLoops[now.day()] = 1;
60
+ }
61
+ return newLoops;
62
+ }