@@ -8,17 +8,20 @@ import FileOpenIcon from '@mui/icons-material/FileOpen';
88import NoteAddIcon from '@mui/icons-material/NoteAdd' ;
99import SaveIcon from '@mui/icons-material/Save' ;
1010import { MainContext } from '../../contexts/MainContextProvider' ;
11- import { setPageIndex } from '../../reducers/MainReducer/Actions' ;
11+ import { openWebSite , setPageIndex } from '../../reducers/MainReducer/Actions' ;
1212import { VaultContext } from '../../contexts/VaultContextProvider' ;
1313import CreateVaultDialog from '../../components/CreateVaultDialog' ;
14+ import { setVault } from '../../reducers/VaultReducer/Actions' ;
15+ import VaultCard from '../../components/VaultCard' ;
1416
1517const Vault = ( ) => {
1618 const [ state , d1 ] = useContext ( MainContext ) ;
17- const [ vaultState ] = useContext ( VaultContext ) ;
19+ const [ vaultState , d3 ] = useContext ( VaultContext ) ;
1820
1921 const language = state . languages [ state . languageIndex ] ;
2022 const { vault } = vaultState ;
2123
24+ const [ phrase , setPhrase ] = useState ( '' ) ;
2225 const [ createDialogOpen , setCreateDialogOpen ] = useState ( false ) ;
2326
2427 /**
@@ -29,13 +32,54 @@ const Vault = () => {
2932 if ( ! key || key . length === 0 ) {
3033 return ;
3134 }
32- console . log ( key ) ;
35+ setPhrase ( key ) ;
36+ d3 ( setVault ( [ ] ) ) ;
37+ } ;
38+
39+ /**
40+ * Open a password URL
41+ * @param url The URL that needs to be opened
42+ */
43+ const openPassword = ( url ) => {
44+ openWebSite ( url ) ;
45+ } ;
46+
47+ /**
48+ * Delete a password from the vault
49+ * @param id The ID of the password
50+ */
51+ const deletePassword = ( id ) => {
52+ const newVault = JSON . parse ( JSON . stringify ( vault ) ) . filter ( ( p ) => p . id !== id ) ;
53+ d3 ( setVault ( newVault ) ) ;
3354 } ;
3455
3556 useEffect ( ( ) => {
3657 d1 ( setPageIndex ( 4 ) ) ;
3758 } , [ ] ) ;
3859
60+ const gridItems = vault && vault . length > 0 ? vault . map ( ( item ) => (
61+ < Grid
62+ key = { item . id }
63+ item
64+ xs = { 12 }
65+ md = { 4 }
66+ lg = { 3 }
67+ >
68+ < VaultCard
69+ id = { item . id }
70+ title = { item . title }
71+ description = { item . description }
72+ url = { item . url }
73+ openLabel = { language . open }
74+ editLabel = { language . edit }
75+ deleteLabel = { language . delete }
76+ onClick = { openPassword }
77+ onEdit = { ( ) => { } }
78+ onDelete = { deletePassword }
79+ />
80+ </ Grid >
81+ ) ) : null ;
82+
3983 return (
4084 < Container >
4185 < Grid container spacing = { 2 } >
@@ -44,47 +88,46 @@ const Vault = () => {
4488 { language . vault }
4589 </ Typography >
4690 </ Grid >
47- < Grid item xs = { 12 } md = { 12 } lg = { 12 } >
48- < Box sx = { { '& > :not(style)' : { m : 1 } } } >
49- < Fab
50- color = "primary"
51- aria-label = { language . open }
52- sx = { {
53- position : 'absolute' ,
54- bottom : 16 ,
55- right : 16 ,
56- } }
57- >
58- < FileOpenIcon />
59- </ Fab >
60- < Fab
61- color = "primary"
62- aria-label = { language . new }
63- sx = { {
64- position : 'absolute' ,
65- bottom : 16 ,
66- right : 84 ,
67- } }
68- onClick = { ( ) => setCreateDialogOpen ( true ) }
69- >
70- < NoteAddIcon />
71- </ Fab >
72- { vault ? (
73- < Fab
74- color = "primary"
75- aria-label = { language . save }
76- sx = { {
77- position : 'absolute' ,
78- bottom : 16 ,
79- right : 152 ,
80- } }
81- >
82- < SaveIcon />
83- </ Fab >
84- ) : null }
85- </ Box >
86- </ Grid >
91+ { gridItems }
8792 </ Grid >
93+ < Box sx = { { '& > :not(style)' : { m : 1 } } } >
94+ < Fab
95+ color = "primary"
96+ aria-label = { language . open }
97+ sx = { {
98+ position : 'absolute' ,
99+ bottom : 16 ,
100+ right : 16 ,
101+ } }
102+ >
103+ < FileOpenIcon />
104+ </ Fab >
105+ < Fab
106+ color = "primary"
107+ aria-label = { language . new }
108+ sx = { {
109+ position : 'absolute' ,
110+ bottom : 16 ,
111+ right : 84 ,
112+ } }
113+ onClick = { ( ) => setCreateDialogOpen ( true ) }
114+ >
115+ < NoteAddIcon />
116+ </ Fab >
117+ { vault ? (
118+ < Fab
119+ color = "primary"
120+ aria-label = { language . save }
121+ sx = { {
122+ position : 'absolute' ,
123+ bottom : 16 ,
124+ right : 152 ,
125+ } }
126+ >
127+ < SaveIcon />
128+ </ Fab >
129+ ) : null }
130+ </ Box >
88131 < CreateVaultDialog
89132 open = { createDialogOpen }
90133 onClose = { ( ) => setCreateDialogOpen ( false ) }
0 commit comments