@campxdev/shared 1.5.2 → 1.5.4
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,5 +1,6 @@
|
|
|
1
1
|
import { Tune } from '@mui/icons-material'
|
|
2
2
|
import { Box, styled } from '@mui/material'
|
|
3
|
+
import { useEffect, useState } from 'react'
|
|
3
4
|
|
|
4
5
|
const StyledButtonWrapper = styled(Box)<{ size: 'regular' | 'large' }>(
|
|
5
6
|
({ theme, size }) => ({
|
|
@@ -37,14 +38,15 @@ export default function FilterButton({
|
|
|
37
38
|
...props
|
|
38
39
|
}: {
|
|
39
40
|
onClick: (e: any) => void
|
|
40
|
-
filtersApplied?: boolean
|
|
41
41
|
size?: 'regular' | 'large'
|
|
42
|
+
filtersApplied?: any
|
|
42
43
|
}) {
|
|
43
44
|
const handleClick = (e) => {
|
|
44
45
|
e.stopPropagation()
|
|
45
46
|
if (!onClick) return
|
|
46
47
|
onClick(e)
|
|
47
48
|
}
|
|
49
|
+
|
|
48
50
|
return (
|
|
49
51
|
<StyledButtonWrapper size={size} {...props} onClick={handleClick}>
|
|
50
52
|
{filtersApplied && <StyledNotify />}
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export default function useFilters(initialState, key) {
|
|
4
|
+
const [filters, setFilters] = useState(initialState)
|
|
5
|
+
const [filtersApplied, setFiltersApplied] = useState(false)
|
|
6
|
+
|
|
7
|
+
function onFilterChange(modified) {
|
|
8
|
+
setFilters({
|
|
9
|
+
...filters,
|
|
10
|
+
...modified,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const sessionData = Object.keys(modified).reduce((acc, curr) => {
|
|
14
|
+
if (!!modified[curr]) {
|
|
15
|
+
acc.push({ key: curr, value: modified[curr] })
|
|
16
|
+
}
|
|
17
|
+
return acc
|
|
18
|
+
}, [])
|
|
19
|
+
|
|
20
|
+
if (sessionData?.length > 0) {
|
|
21
|
+
sessionStorage.setItem(key, JSON.stringify(sessionData))
|
|
22
|
+
setFiltersApplied(true)
|
|
23
|
+
} else {
|
|
24
|
+
sessionStorage.removeItem(key)
|
|
25
|
+
setFiltersApplied(false)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function clearFilters() {
|
|
30
|
+
setFilters(initialState)
|
|
31
|
+
setFiltersApplied(false)
|
|
32
|
+
sessionStorage.removeItem(key)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const prevFilters = getSessionFilters()
|
|
37
|
+
setFilters({
|
|
38
|
+
...filters,
|
|
39
|
+
...prevFilters,
|
|
40
|
+
})
|
|
41
|
+
}, [])
|
|
42
|
+
|
|
43
|
+
const getSessionFilters = () => {
|
|
44
|
+
try {
|
|
45
|
+
if (sessionStorage.getItem(key)) {
|
|
46
|
+
setFiltersApplied(true)
|
|
47
|
+
const parsed = JSON.parse(sessionStorage.getItem(key))
|
|
48
|
+
const filters = parsed?.reduce(
|
|
49
|
+
(acc, curr) => ({ ...acc, [curr.key]: curr.value }),
|
|
50
|
+
{},
|
|
51
|
+
)
|
|
52
|
+
return filters
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
filters,
|
|
59
|
+
onFilterChange,
|
|
60
|
+
clearFilters,
|
|
61
|
+
filtersApplied,
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/theme/muiTheme.ts
CHANGED
|
@@ -166,13 +166,13 @@ const muiTheme = createTheme({
|
|
|
166
166
|
fontWeight: 600,
|
|
167
167
|
},
|
|
168
168
|
subtitle1: {
|
|
169
|
-
fontSize: '
|
|
170
|
-
fontWeight:
|
|
171
|
-
color: '#
|
|
169
|
+
fontSize: '14px',
|
|
170
|
+
fontWeight: 600,
|
|
171
|
+
color: '#121212b3',
|
|
172
172
|
},
|
|
173
173
|
subtitle2: {
|
|
174
174
|
fontSize: '13px',
|
|
175
|
-
fontWeight:
|
|
175
|
+
fontWeight: 600,
|
|
176
176
|
color: '#959595',
|
|
177
177
|
},
|
|
178
178
|
},
|