1
- import {
2
- ActionIcon ,
3
- Alert ,
4
- Badge ,
5
- Box ,
6
- Button ,
7
- Checkbox ,
8
- Code ,
9
- createStyles ,
10
- Paper ,
11
- Skeleton ,
12
- Text ,
13
- Title ,
14
- } from '@mantine/core' ;
15
- import { useModals } from '@mantine/modals' ;
1
+ import { ActionIcon , Badge , createStyles , Paper , Skeleton , Title , Tooltip } from '@mantine/core' ;
16
2
import { Prisma } from '@prisma/client' ;
17
- import { IconEdit , IconX } from '@tabler/icons' ;
3
+ import { IconEdit , IconRefresh , IconX } from '@tabler/icons' ;
18
4
import { contrastColor } from 'contrast-color' ;
19
- import { useState } from 'react' ;
20
5
import stc from 'string-to-color' ;
6
+ import { useRefreshModal } from './refreshMetadata' ;
7
+ import { useRemoveModal } from './removeManga' ;
21
8
import { useUpdateModal } from './updateManga' ;
22
9
23
10
const useStyles = createStyles ( ( theme , _params , getRef ) => ( {
@@ -49,6 +36,9 @@ const useStyles = createStyles((theme, _params, getRef) => ({
49
36
[ `&:hover .${ getRef ( 'editButton' ) } ` ] : {
50
37
display : 'flex' ,
51
38
} ,
39
+ [ `&:hover .${ getRef ( 'refreshButton' ) } ` ] : {
40
+ display : 'flex' ,
41
+ } ,
52
42
} ,
53
43
removeButton : {
54
44
ref : getRef ( 'removeButton' ) ,
@@ -57,6 +47,18 @@ const useStyles = createStyles((theme, _params, getRef) => ({
57
47
top : - 5 ,
58
48
display : 'none' ,
59
49
} ,
50
+ refreshButton : {
51
+ ref : getRef ( 'refreshButton' ) ,
52
+ backgroundColor : theme . white ,
53
+ color : theme . colors . blue [ 6 ] ,
54
+ position : 'absolute' ,
55
+ right : 10 ,
56
+ bottom : 50 ,
57
+ display : 'none' ,
58
+ '&:hover' : {
59
+ backgroundColor : theme . colors . gray [ 0 ] ,
60
+ } ,
61
+ } ,
60
62
editButton : {
61
63
ref : getRef ( 'editButton' ) ,
62
64
backgroundColor : theme . white ,
@@ -93,92 +95,21 @@ interface MangaCardProps {
93
95
manga : MangaWithLibraryAndMetadata ;
94
96
onRemove : ( shouldRemoveFiles : boolean ) => void ;
95
97
onUpdate : ( ) => void ;
98
+ onRefresh : ( ) => void ;
96
99
onClick : ( ) => void ;
97
100
}
98
101
99
- function RemoveModalContent ( {
100
- title,
101
- onRemove,
102
- onClose,
103
- } : {
104
- title : string ;
105
- onRemove : ( shouldRemoveFiles : boolean ) => void ;
106
- onClose : ( ) => void ;
107
- } ) {
108
- const [ shouldRemoveFiles , setShouldRemoveFiles ] = useState ( false ) ;
109
- return (
110
- < >
111
- < Text mb = { 4 } size = "sm" >
112
- Are you sure you want to remove
113
- < Code className = "text-base font-bold" color = "red" >
114
- { title }
115
- </ Code >
116
- ?
117
- </ Text >
118
- < Alert
119
- icon = {
120
- < Checkbox
121
- checked = { shouldRemoveFiles }
122
- color = "red"
123
- onChange = { ( event ) => setShouldRemoveFiles ( event . currentTarget . checked ) }
124
- />
125
- }
126
- title = "Remove files?"
127
- color = "red"
128
- >
129
- This action is destructive and all downloaded files will be removed
130
- </ Alert >
131
- < Box
132
- sx = { ( theme ) => ( {
133
- display : 'flex' ,
134
- gap : theme . spacing . xs ,
135
- justifyContent : 'end' ,
136
- marginTop : theme . spacing . md ,
137
- } ) }
138
- >
139
- < Button variant = "default" color = "dark" onClick = { onClose } >
140
- Cancel
141
- </ Button >
142
- < Button
143
- variant = "filled"
144
- color = "red"
145
- onClick = { ( ) => {
146
- onRemove ( shouldRemoveFiles ) ;
147
- onClose ( ) ;
148
- } }
149
- >
150
- Remove
151
- </ Button >
152
- </ Box >
153
- </ >
154
- ) ;
155
- }
156
-
157
- const useRemoveModal = ( title : string , onRemove : ( shouldRemoveFiles : boolean ) => void ) => {
158
- const modals = useModals ( ) ;
159
-
160
- const openRemoveModal = ( ) => {
161
- const id = modals . openModal ( {
162
- title : `Remove ${ title } ?` ,
163
- centered : true ,
164
- children : < RemoveModalContent title = { title } onRemove = { onRemove } onClose = { ( ) => modals . closeModal ( id ) } /> ,
165
- } ) ;
166
- } ;
167
-
168
- return openRemoveModal ;
169
- } ;
170
-
171
102
export function SkeletonMangaCard ( ) {
172
103
const { classes } = useStyles ( ) ;
173
104
174
105
return < Skeleton radius = "md" className = { classes . skeletonCard } /> ;
175
106
}
176
107
177
- export function MangaCard ( { manga, onRemove, onUpdate, onClick } : MangaCardProps ) {
108
+ export function MangaCard ( { manga, onRemove, onUpdate, onRefresh , onClick } : MangaCardProps ) {
178
109
const { classes } = useStyles ( ) ;
179
110
const removeModal = useRemoveModal ( manga . title , onRemove ) ;
111
+ const refreshModal = useRefreshModal ( manga . title , onRefresh ) ;
180
112
const updateModal = useUpdateModal ( manga , onUpdate ) ;
181
-
182
113
return (
183
114
< Paper
184
115
onClick = { onClick }
@@ -202,19 +133,36 @@ export function MangaCard({ manga, onRemove, onUpdate, onClick }: MangaCardProps
202
133
>
203
134
< IconX size = { 16 } />
204
135
</ ActionIcon >
205
- < ActionIcon
206
- color = "blue"
207
- variant = "light"
208
- size = "lg"
209
- radius = "xl"
210
- className = { classes . editButton }
211
- onClick = { ( e : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => {
212
- e . stopPropagation ( ) ;
213
- updateModal ( ) ;
214
- } }
215
- >
216
- < IconEdit size = { 18 } />
217
- </ ActionIcon >
136
+ < Tooltip withinPortal withArrow label = "Refresh Metadata" position = "left" >
137
+ < ActionIcon
138
+ color = "teal"
139
+ variant = "filled"
140
+ size = "lg"
141
+ radius = "xl"
142
+ className = { classes . refreshButton }
143
+ onClick = { ( e : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => {
144
+ e . stopPropagation ( ) ;
145
+ refreshModal ( ) ;
146
+ } }
147
+ >
148
+ < IconRefresh size = { 18 } />
149
+ </ ActionIcon >
150
+ </ Tooltip >
151
+ < Tooltip withinPortal withArrow label = "Edit" position = "left" >
152
+ < ActionIcon
153
+ color = "blue"
154
+ variant = "light"
155
+ size = "lg"
156
+ radius = "xl"
157
+ className = { classes . editButton }
158
+ onClick = { ( e : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => {
159
+ e . stopPropagation ( ) ;
160
+ updateModal ( ) ;
161
+ } }
162
+ >
163
+ < IconEdit size = { 18 } />
164
+ </ ActionIcon >
165
+ </ Tooltip >
218
166
< div >
219
167
< Badge
220
168
sx = { { backgroundColor : stc ( manga . source ) , color : contrastColor ( { bgColor : stc ( manga . source ) } ) } }
0 commit comments