@@ -60,7 +60,7 @@ class StoragesTab extends React.Component {
60
60
loadAttachmentStorage ( ) {
61
61
const promises = [ ]
62
62
this . props . data . noteMap . map ( note => {
63
- const promise = attachmentManagement . getAttachments (
63
+ const promise = attachmentManagement . getAttachmentsPathAndStatus (
64
64
note . content ,
65
65
note . storage ,
66
66
note . key
@@ -69,7 +69,10 @@ class StoragesTab extends React.Component {
69
69
} )
70
70
71
71
Promise . all ( promises )
72
- . then ( data => this . setState ( { attachments : data } ) )
72
+ . then ( data => {
73
+ const result = data . reduce ( ( acc , curr ) => acc . concat ( curr ) , [ ] )
74
+ this . setState ( { attachments : result } )
75
+ } )
73
76
. catch ( console . error )
74
77
}
75
78
@@ -118,32 +121,24 @@ class StoragesTab extends React.Component {
118
121
const { data, boundingBox } = this . props
119
122
const { attachments } = this . state
120
123
121
- const totalUnusedAttachments = attachments
122
- . reduce ( ( acc , curr ) => acc + curr . attachmentsNotInNotePaths . length , 0 )
123
- const totalInuseAttachments = attachments
124
- . reduce ( ( acc , curr ) => acc + curr . attachmentsInNotePaths . length , 0 )
125
- const totalAttachments = totalUnusedAttachments + totalInuseAttachments
124
+ const unusedAttachments = attachments . filter ( attachment => ! attachment . isInUse )
125
+ const inUseAttachments = attachments . filter ( attachment => attachment . isInUse )
126
126
127
- const unusedAttachments = attachments . reduce ( ( acc , curr ) => {
128
- acc . push ( curr . attachmentsNotInNotePaths )
129
- return acc
130
- } , [ ] )
127
+ const totalUnusedAttachments = unusedAttachments . length
128
+ const totalInuseAttachments = inUseAttachments . length
129
+ const totalAttachments = totalUnusedAttachments + totalInuseAttachments
131
130
132
- const totalUnusedAttachmentsSize = attachments
131
+ const totalUnusedAttachmentsSize = unusedAttachments
133
132
. reduce ( ( acc , curr ) => {
134
- return acc + curr . attachmentsNotInNotePaths . reduce ( ( racc , rcurr ) => {
135
- const stats = fs . statSync ( rcurr )
136
- const fileSizeInBytes = stats . size
137
- return racc + fileSizeInBytes
138
- } , 0 )
133
+ const stats = fs . statSync ( curr . path )
134
+ const fileSizeInBytes = stats . size
135
+ return acc + fileSizeInBytes
139
136
} , 0 )
140
- const totalInuseAttachmentsSize = attachments
137
+ const totalInuseAttachmentsSize = inUseAttachments
141
138
. reduce ( ( acc , curr ) => {
142
- return acc + curr . attachmentsInNotePaths . reduce ( ( racc , rcurr ) => {
143
- const stats = fs . statSync ( rcurr )
144
- const fileSizeInBytes = stats . size
145
- return racc + fileSizeInBytes
146
- } , 0 )
139
+ const stats = fs . statSync ( curr . path )
140
+ const fileSizeInBytes = stats . size
141
+ return acc + fileSizeInBytes
147
142
} , 0 )
148
143
const totalAttachmentsSize = totalUnusedAttachmentsSize + totalInuseAttachmentsSize
149
144
0 commit comments