Skip to content

Commit 51a7a38

Browse files
committed
add back population of fields to stored objects
if we don't do this, there is odd behavior with the rendering of objects. sometimes duplicates show up (probably how For / reconcile works under the hood)
1 parent f94b750 commit 51a7a38

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/components/UploadQueue.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,30 @@ const mapOfflineQueueItems = (data: AthenaOfflineQueueResponse): UploadQueueItem
4444
})),
4545
)
4646

47-
const extractAttributes = (url: string) => {
48-
const parsed = new URL(url)
47+
interface UploadQueueItemWithAttributes extends UploadQueueItem {
48+
route: string
49+
segment: number
50+
filename: string
51+
isFirehose: boolean
52+
}
53+
54+
const populateAttributes = (item: UploadQueueItem): UploadQueueItemWithAttributes => {
55+
const parsed = new URL(item.url)
4956
const parts = parsed.pathname.split('/')
5057
if (parsed.hostname === 'upload.commadotai.com') {
51-
return { route: parts[2], segment: parseInt(parts[3], 10), filename: parts[4], isFirehose: true }
58+
return { ...item, route: parts[2], segment: parseInt(parts[3], 10), filename: parts[4], isFirehose: true }
5259
}
53-
return { route: parts[3], segment: parseInt(parts[4], 10), filename: parts[5], isFirehose: false }
60+
return { ...item, route: parts[3], segment: parseInt(parts[4], 10), filename: parts[5], isFirehose: false }
5461
}
5562

56-
const UploadQueueRow: VoidComponent<{ cancel: (ids: string[]) => void; item: UploadQueueItem }> = ({ cancel, item }) => {
57-
const attrs = extractAttributes(item.url)
63+
const UploadQueueRow: VoidComponent<{ cancel: (ids: string[]) => void; item: UploadQueueItemWithAttributes }> = ({ cancel, item }) => {
5864
return (
5965
<div class="flex flex-col">
6066
<div class="flex items-center justify-between flex-wrap mb-1 gap-x-4 min-w-0">
6167
<div class="flex items-center min-w-0 flex-1">
62-
<Icon class="text-on-surface-variant flex-shrink-0 mr-2" name={attrs.isFirehose ? 'local_fire_department' : 'person'} />
68+
<Icon class="text-on-surface-variant flex-shrink-0 mr-2" name={item.isFirehose ? 'local_fire_department' : 'person'} />
6369
<div class="flex min-w-0 gap-1">
64-
<span class="text-body-sm font-mono truncate text-on-surface">{[attrs.route, attrs.segment, attrs.filename].join(' ')}</span>
70+
<span class="text-body-sm font-mono truncate text-on-surface">{[item.route, item.segment, item.filename].join(' ')}</span>
6571
</div>
6672
</div>
6773
<div class="flex items-center gap-0.5 flex-shrink-0 justify-end">
@@ -94,12 +100,12 @@ const UploadQueue: VoidComponent<{ dongleId: string }> = (props) => {
94100
const offlineQueue = createQuery(() => queries.getOffline(props.dongleId))
95101
const cancel = queries.cancelUpload(props.dongleId)
96102

97-
const [items, setItems] = createStore<UploadQueueItem[]>([])
103+
const [items, setItems] = createStore<UploadQueueItemWithAttributes[]>([])
98104

99105
createEffect(() => {
100106
const online = onlineQueue.isSuccess ? (onlineQueue.data?.result ?? []) : []
101107
const offline = offlineQueue.isSuccess ? mapOfflineQueueItems(offlineQueue.data ?? []) : []
102-
const sorted = [...online, ...offline].sort((a, b) => b.progress - a.progress)
108+
const sorted = [...online, ...offline].map(populateAttributes).sort((a, b) => b.progress - a.progress)
103109
setItems(reconcile(sorted))
104110
})
105111

0 commit comments

Comments
 (0)