Skip to content
This repository was archived by the owner on Jun 17, 2026. It is now read-only.

Commit 11cba39

Browse files
feat: update bulk download at multiple sizes
1 parent 1ef4042 commit 11cba39

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

src/components/AssetMetadata/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import {Box, Button, Flex, Inline, Stack, Text} from '@sanity/ui'
33
import {Asset, AssetItem} from '@types'
44
import format from 'date-fns/format'
55
import filesize from 'filesize'
6+
import {ReactNode, useState} from 'react'
7+
import Select from 'react-select'
68
import {useColorScheme} from 'sanity'
7-
import React, {useState, ReactNode} from 'react'
9+
import {reactSelectComponents, reactSelectStyles} from '../../styled/react-select/alt'
810
import getAssetResolution from '../../utils/getAssetResolution'
911
import {isImageAsset} from '../../utils/typeGuards'
1012
import ButtonAssetCopy from '../ButtonAssetCopy'
11-
import Select from 'react-select'
12-
import {reactSelectComponents, reactSelectStyles} from '../../styled/react-select/alt'
1313

1414
type Props = {
1515
asset: Asset
@@ -56,10 +56,10 @@ const AssetMetadata = (props: Props) => {
5656
{value: 1080, label: '1080w'},
5757
{value: 720, label: '720w'}
5858
]
59-
const handleSizeSelect = (option: Option) => {
59+
const handleSizeSelect = (option: Option[]) => {
6060
setOption(option)
6161
}
62-
const [option, setOption] = useState(options[0])
62+
const [option, setOption] = useState([options[0]])
6363
interface Option {
6464
label: string
6565
value: number
@@ -80,11 +80,13 @@ const AssetMetadata = (props: Props) => {
8080

8181
// Callbacks
8282
const handleDownload = () => {
83-
if (option.value == 0) {
84-
window.location.href = `${asset.url}?dl=${asset.originalFilename}`
85-
} else {
86-
window.location.href = `${asset.url}?w=${option.value}&dl=${asset.originalFilename}`
87-
}
83+
option.forEach(file => {
84+
if (file.value == 0) {
85+
window.open(`${asset.url}?dl=${asset.originalFilename}`)
86+
} else {
87+
window.open(`${asset.url}?w=${file.value}&dl=${asset.originalFilename}`)
88+
}
89+
})
8890
}
8991

9092
return (
@@ -162,10 +164,11 @@ const AssetMetadata = (props: Props) => {
162164
isSearchable
163165
name="downloadSize"
164166
options={options}
167+
isMulti
165168
defaultValue={options[0]}
166169
menuPlacement="top"
167170
styles={reactSelectStyles(scheme)}
168-
onChange={value => handleSizeSelect(value as Option)}
171+
onChange={value => handleSizeSelect(value as Option[])}
169172
/>
170173
</Flex>
171174
{/* Copy to clipboard */}

src/styled/react-select/alt.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {Box, Card, rem, studioTheme, Text, ThemeColorSchemeKey} from '@sanity/ui'
2-
import React from 'react'
32
import {components, StylesConfig} from 'react-select'
43
import {Virtuoso} from 'react-virtuoso'
54
import {getSchemeColor} from '../../utils/getSchemeColor'
@@ -92,6 +91,14 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
9291
dropdownIndicator: styles => ({
9392
...styles,
9493
padding: 6
94+
}),
95+
multiValueLabel: styles => ({
96+
...styles,
97+
padding: '16px 6px'
98+
}),
99+
multiValueRemove: styles => ({
100+
...styles,
101+
color: 'var(--card-bg-color)'
95102
})
96103
}
97104
}

0 commit comments

Comments
 (0)