ywana-core8 0.0.829 → 0.0.830

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.829",
3
+ "version": "0.0.830",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -0,0 +1,41 @@
1
+ .calendar-row {
2
+ border: solid 1px rgb(0, 0, 0);
3
+ overflow-x: auto;
4
+ }
5
+
6
+ .months-row {
7
+ display: flex;
8
+ overflow: visible;
9
+ }
10
+
11
+ .month-cell {
12
+ border: solid 1px rgb(220, 220, 220);
13
+ min-width: 3rem;
14
+ height: 1.4rem;
15
+ display: flex;
16
+ flex-direction: column;
17
+ align-items: center;
18
+ justify-content: center;
19
+ }
20
+
21
+ .day-cell {
22
+ padding: .5rem 0;
23
+ border: solid 1px rgb(220, 220, 220);
24
+ display: flex;
25
+ flex-direction: column;
26
+ align-items: center;
27
+ justify-content: center;
28
+
29
+ }
30
+
31
+ .weekday {
32
+ font-size: .6rem;
33
+ font-weight: 400;
34
+ color:rgb(143, 143, 143)
35
+ }
36
+
37
+ .daynum {
38
+ font-size: .8rem;
39
+ font-weight: 600;
40
+ padding: .2rem 0;
41
+ }
@@ -0,0 +1,66 @@
1
+ import React from 'react'
2
+ import "./calendar.css"
3
+
4
+
5
+ export const Calendar = ({ from, to }) => {
6
+ const days = [];
7
+ const day = new Date(from);
8
+ const lastDay = new Date(to);
9
+ while (day <= lastDay) {
10
+ days.push({
11
+ day: day.getDate(),
12
+ weekday: day.toLocaleString('en-US', { weekday: 'short' }),
13
+ month: day.toLocaleString('en-US', { month: 'short' }),
14
+ });
15
+ day.setDate(day.getDate() + 1);
16
+ }
17
+
18
+ const uniqueMonths = Array.from(
19
+ new Set(days.map(({ month }) => month))
20
+ );
21
+
22
+ const monthWidths = uniqueMonths.map((month) => {
23
+ const monthDays = days.filter((day) => day.month === month);
24
+ return `${monthDays.length * 2}rem`;
25
+ });
26
+
27
+ const dayWidth = '2rem';
28
+
29
+ return (
30
+ <div className='calendar-row'>
31
+ <div className="months-row" style={{ display: 'flex' }}>
32
+ {uniqueMonths.map((month, index) => (
33
+ <div
34
+ className="month-cell"
35
+ key={month}
36
+ style={{
37
+ flex: '0 0 auto',
38
+ textAlign: 'center',
39
+ fontWeight: 'bold',
40
+ width: monthWidths[index],
41
+ }}
42
+ >
43
+ {month} {new Date(from).getFullYear()}
44
+ </div>
45
+ ))}
46
+ </div>
47
+ <div style={{ display: 'flex' }}>
48
+ {days.map(({ day, weekday, month }) => (
49
+ <div className='day-cell' key={day} style={{ flex: 1, textAlign: 'center', minWidth: dayWidth }}>
50
+ <div className="weekday">{weekday.substring(0,2)}</div>
51
+ <div className="daynum">{day}</div>
52
+ </div>
53
+ ))}
54
+ </div>
55
+ </div>
56
+ );
57
+ };
58
+
59
+
60
+ const CalendarTest = (props) => {
61
+ return (
62
+ <>
63
+ <Calendar from="2023-01-01" to="2023-03-03" />
64
+ </>
65
+ )
66
+ }
@@ -17,17 +17,10 @@ export const TaskContextProvider = (props) => {
17
17
  const { host, url = "/tasks", frequency = 5000, children, listeners = {} } = props
18
18
  const API = CollectionAPI(url, host)
19
19
  const _listeners = Object.assign({}, listeners)
20
- const [filters, setFilters] = useState({})
21
20
 
22
- useEffect(() => {
23
- console.log("TaskContext", filters)
24
- }, [filters])
25
-
26
- async function tasks(filters2, likes) {
21
+ async function tasks(filters, likes) {
27
22
  try {
28
- const filters3 = Object.assign({}, filters, filters2)
29
- console.log("tasks", filters, filters3)
30
- const response = await API.all(filters3, likes);
23
+ const response = await API.all(filters, likes);
31
24
  return response;
32
25
  } catch (error) {
33
26
  console.log("tasks error", error);
@@ -81,11 +74,7 @@ export const TaskContextProvider = (props) => {
81
74
 
82
75
  useEffect(() => {
83
76
  const interval = setInterval(async () => {
84
-
85
- console.log("TASKS REFRESH", filters)
86
- const tasks = await API.all(filters)
87
-
88
- // find task for each listener
77
+ const tasks = await API.all({ state: TASK_STATES.RUNNING})
89
78
  Object.keys(_listeners).forEach(taskID => {
90
79
  const task = tasks.find(task => task.id === taskID)
91
80
  if (task) {
@@ -93,7 +82,6 @@ export const TaskContextProvider = (props) => {
93
82
  if (listener) listener(task)
94
83
  }
95
84
  })
96
-
97
85
  }, frequency)
98
86
  return () => clearInterval(interval)
99
87
  }, [])
@@ -105,8 +93,7 @@ export const TaskContextProvider = (props) => {
105
93
  updateTask,
106
94
  removeTask,
107
95
  addListener,
108
- removeListener,
109
- setFilters
96
+ removeListener
110
97
  };
111
98
 
112
99
  return (
@@ -162,27 +149,20 @@ export const TaskMonitor = (props) => {
162
149
  const { title = "Task Monitor", filters = {}, editors } = props
163
150
  const context = useContext(TaskContext)
164
151
  const [tasks = [], setTasks] = useState([])
165
- const [from, setFrom ] = useState()
152
+ const [from, setFrom ] = useState(props.from)
166
153
 
167
154
  useEffect(() => {
168
-
169
- if (props.from) setFrom(props.from)
170
-
171
155
  refresh()
172
-
173
156
  const interval = setInterval(() => {
174
157
  refresh()
175
158
  }, 5000)
176
159
  return () => { clearInterval(interval) }
177
160
  }, [])
178
161
 
179
- useEffect(() => {
180
- console.log("from", from)
181
- if (from) context.setFilters({ from })
182
- }, [from])
183
-
184
162
  async function refresh() {
185
- const tasks = await context.tasks()
163
+ if (from) filters["from"] = from
164
+ console.log("refresh", filters)
165
+ const tasks = await context.tasks(filters)
186
166
  setTasks(tasks)
187
167
  }
188
168