@@ -43,6 +43,7 @@ export default function BookDetail({ user, book, topics }: BookDetailProps) {
43
43
const [ bookData , setBookData ] = useState < BookType > ( book ) ;
44
44
const [ antolinResults , setAntolinResults ] = useState ( null ) ;
45
45
const [ returnBookSnackbar , setReturnBookSnackbar ] = useState ( false ) ;
46
+ const [ saveBookSnackbar , setSaveBookSnackbar ] = useState ( false ) ;
46
47
47
48
useEffect ( ( ) => {
48
49
setBookData ( book ) ;
@@ -84,6 +85,17 @@ export default function BookDetail({ user, book, topics }: BookDetailProps) {
84
85
setReturnBookSnackbar ( false ) ;
85
86
} ;
86
87
88
+ const handleCloseSaveBookSnackbar = (
89
+ event ?: React . SyntheticEvent | Event ,
90
+ reason ?: string
91
+ ) => {
92
+ if ( reason === "clickaway" ) {
93
+ return ;
94
+ }
95
+
96
+ setSaveBookSnackbar ( false ) ;
97
+ } ;
98
+
87
99
const handleSaveButton = ( ) => {
88
100
console . log ( "Saving book " , bookData ) ;
89
101
@@ -101,7 +113,9 @@ export default function BookDetail({ user, book, topics }: BookDetailProps) {
101
113
body : JSON . stringify ( { ...savingBook , rentedDate, dueDate } ) ,
102
114
} )
103
115
. then ( ( res ) => res . json ( ) )
104
- . then ( ( data ) => { } ) ;
116
+ . then ( ( data ) => {
117
+ setSaveBookSnackbar ( true ) ;
118
+ } ) ;
105
119
} ;
106
120
107
121
const handleReturnBookButton = ( userid : number ) => {
@@ -149,7 +163,7 @@ export default function BookDetail({ user, book, topics }: BookDetailProps) {
149
163
/>
150
164
< Snackbar
151
165
open = { returnBookSnackbar }
152
- autoHideDuration = { 8000 }
166
+ autoHideDuration = { 4000 }
153
167
onClose = { handleCloseReturnBookSnackbar }
154
168
>
155
169
< Alert
@@ -160,6 +174,19 @@ export default function BookDetail({ user, book, topics }: BookDetailProps) {
160
174
Buch zurückgegeben, super!
161
175
</ Alert >
162
176
</ Snackbar >
177
+ < Snackbar
178
+ open = { saveBookSnackbar }
179
+ autoHideDuration = { 4000 }
180
+ onClose = { handleCloseSaveBookSnackbar }
181
+ >
182
+ < Alert
183
+ onClose = { handleCloseSaveBookSnackbar }
184
+ severity = "success"
185
+ sx = { { width : "100%" } }
186
+ >
187
+ Buch gespeichert, gut gemacht!
188
+ </ Alert >
189
+ </ Snackbar >
163
190
</ ThemeProvider >
164
191
</ Layout >
165
192
) ;
0 commit comments