ywana-core8 0.0.797 → 0.0.799

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.797",
3
+ "version": "0.0.799",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -14,7 +14,10 @@ export const CollectionContextProvider = (props) => {
14
14
  const [all, setAll] = useState([])
15
15
  const [filters, setFilters] = useState(filtersValue)
16
16
  const [likes, setLikes] = useState([])
17
+
17
18
  const [customFilters, setCustomFilters] = useState({})
19
+ const [filtered, setFiltered] = useState([])
20
+
18
21
  const [queries, setQueries] = useState([])
19
22
  const [selected, setSelected] = useState(null)
20
23
 
@@ -28,21 +31,28 @@ export const CollectionContextProvider = (props) => {
28
31
  return () => {
29
32
  mounted = false;
30
33
  }
31
- }, [filters, customFilters])
34
+ }, [filters])
35
+
36
+ useEffect(() => {
37
+ runCustomFilters()
38
+ }, [customFilters])
32
39
 
33
40
  async function load() {
34
41
 
42
+ /*
35
43
  const runCustomFilters = (all) => {
36
44
  const cfs = Object.values(customFilters)
37
45
  const data = cfs.length ? cfs.reduce((acc, filter) => filter(acc), all) : all;
38
46
  return data
39
47
  }
48
+ */
40
49
 
41
50
  try {
42
51
  const response = await API.all(filters, likes, page);
43
52
  const next = field ? response[field] : response;
44
- const data = runCustomFilters(next)
45
- return data
53
+ //const data = runCustomFilters(next)
54
+ //return data
55
+ return next;
46
56
  } catch (error) {
47
57
  console.log(error)
48
58
  }
@@ -57,7 +67,7 @@ export const CollectionContextProvider = (props) => {
57
67
  console.log(error)
58
68
  }
59
69
  }
60
-
70
+
61
71
  async function select(id) {
62
72
  if (fetching) {
63
73
  const result = await fetch(id)
@@ -85,6 +95,12 @@ export const CollectionContextProvider = (props) => {
85
95
  setCustomFilters(next)
86
96
  return
87
97
  }
98
+
99
+ function runCustomFilters() {
100
+ const cfs = Object.values(customFilters)
101
+ const data = cfs.length ? cfs.reduce((acc, filter) => filter(acc), all) : all;
102
+ setFiltered(data)
103
+ }
88
104
 
89
105
  async function fetch(id) {
90
106
  try {
@@ -162,6 +178,8 @@ export const CollectionContextProvider = (props) => {
162
178
  setLikes,
163
179
 
164
180
  customFilters,
181
+ filtered,
182
+ runCustomFilters,
165
183
  addCustomFilter,
166
184
  removeCustomFilter,
167
185
 
@@ -1,4 +1,4 @@
1
- import React, { useContext } from 'react'
1
+ import React, { useContext, useEffect, useState } from 'react'
2
2
  import { CheckBox } from '../html'
3
3
  import { CollectionContext, CollectionContextProvider } from './CollectionContext'
4
4
  import { CollectionEditor } from './CollectionEditor'
@@ -42,17 +42,30 @@ const CollectionContextTest = (props) => {
42
42
  }
43
43
 
44
44
  const CustomFilter1 = (props) => {
45
- const collectionContext = useContext(CollectionContext)
46
- const { filters, setFilters } = collectionContext
45
+
46
+ const context = useContext(CollectionContext)
47
+ const [active, setActive] = useState(false)
48
+
49
+ useEffect(() => {
50
+ if (active) {
51
+ context.addCustomFilter("ACTIVE", filter)
52
+ } else {
53
+ context.removeCustomFilter("ACTIVE")
54
+ }
55
+ }, [active])
47
56
 
48
57
  function change(id, value) {
49
- setFilters({ ...filters, [id]: value })
58
+ setActive(value)
59
+ }
60
+
61
+ function filter(all) {
62
+ console.log("CUSTOMFILTER1 DO NOTHING")
63
+ return all
50
64
  }
51
65
 
52
66
  return (
53
67
  <div>
54
- <CheckBox id="custom1" label="Custom Filter 1" value={filters.custom1} onChange={change} />
68
+ <CheckBox id="custom1" label="Custom Filter 1" value={active} onChange={change} />
55
69
  </div>
56
70
  )
57
- }
58
-
71
+ }
@@ -10,7 +10,7 @@ export const CollectionList = (props) => {
10
10
 
11
11
  const { itemRenderer, groupBy, groupRenderer, searchBy = [], sortBy, sortDir } = props
12
12
  const context = useContext(CollectionContext)
13
- const { all = [], selected, filters, customFilters } = context
13
+ const { all = [], filtered=[], selected, filters, customFilters } = context
14
14
  const [search, setSearch] = useState('')
15
15
 
16
16
  function changeSearch(id, value) {
@@ -21,10 +21,10 @@ export const CollectionList = (props) => {
21
21
  context.select(id)
22
22
  }
23
23
 
24
- const searched = searchBy.length > 0 && search.length > 0 ? all.filter(item => {
24
+ const searched = searchBy.length > 0 && search.length > 0 ? filtered.filter(item => {
25
25
  const text = searchBy.map(field => item[field]).join(' ').toLowerCase()
26
26
  return text.includes(search.toLowerCase())
27
- }) : all
27
+ }) : filtered
28
28
 
29
29
  const sorted = sortBy ? searched.sort((a, b) => {
30
30
  const valueA = a[sortBy]