1
1
import { useEffect , useContext , useState , Fragment } from 'react' ;
2
2
import { SnippetsContext } from '../store' ;
3
3
import { SnippetGrid } from '../components/Snippets/SnippetGrid' ;
4
- import { Badge , Button , Card , Layout , List , Spinner } from '../components/UI' ;
4
+ import { Badge , Button , Card , Layout , Spinner } from '../components/UI' ;
5
5
import { Snippet } from '../typescript/interfaces' ;
6
6
7
7
export const Snippets = ( ) : JSX . Element => {
8
8
const { snippets, languageCount, getSnippets, countSnippets } =
9
9
useContext ( SnippetsContext ) ;
10
10
11
11
const [ filter , setFilter ] = useState < string | null > ( null ) ;
12
- const [ localSnippets , setLocalSnippets ] = useState < Snippet [ ] > ( [ ... snippets ] ) ;
12
+ const [ localSnippets , setLocalSnippets ] = useState < Snippet [ ] > ( [ ] ) ;
13
13
14
14
useEffect ( ( ) => {
15
15
getSnippets ( ) ;
16
16
countSnippets ( ) ;
17
17
} , [ ] ) ;
18
18
19
+ useEffect ( ( ) => {
20
+ setLocalSnippets ( [ ...snippets ] ) ;
21
+ } , [ snippets ] ) ;
22
+
19
23
const filterHandler = ( language : string ) => {
20
24
setFilter ( language ) ;
21
25
const filteredSnippets = snippets . filter ( s => s . language === language ) ;
@@ -29,7 +33,7 @@ export const Snippets = (): JSX.Element => {
29
33
30
34
return (
31
35
< Layout >
32
- < div className = 'col-12 col-md-4 col-lg-2 ' >
36
+ < div className = 'col-12 col-md-4 col-lg-3 ' >
33
37
< Card title = 'Filter by language' >
34
38
< Fragment >
35
39
{ languageCount . map ( ( el , idx ) => {
@@ -38,7 +42,7 @@ export const Snippets = (): JSX.Element => {
38
42
return (
39
43
< div
40
44
className = { `d-flex justify-content-between cursor-pointer ${
41
- isActiveFilter && 'text-primary fw-bold'
45
+ isActiveFilter && 'text-dark fw-bold'
42
46
} `}
43
47
key = { idx }
44
48
onClick = { ( ) => filterHandler ( el . language ) }
@@ -52,15 +56,15 @@ export const Snippets = (): JSX.Element => {
52
56
< div className = 'd-grid mt-3' >
53
57
< Button
54
58
text = 'Clear filters'
55
- color = 'primary '
59
+ color = 'dark '
56
60
small
57
61
outline
58
62
handler = { clearFilterHandler }
59
63
/>
60
64
</ div >
61
65
</ Card >
62
66
</ div >
63
- < div className = 'col-12 col-md-8 col-lg-10 ' >
67
+ < div className = 'col-12 col-md-8 col-lg-9 ' >
64
68
{ snippets . length > 0 ? (
65
69
< SnippetGrid snippets = { localSnippets } />
66
70
) : (
0 commit comments