Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/web/src/components/ImageSelectorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ImageSelectorContextData = {
outputFormat: OutputFormat;
outputSizingMode: OutputSizingMode;
processing: boolean;
downloadNameTemplate: string;
};

export const ImageSelectorContext = createContextId<ImageSelectorContextData>('image-selector-context');
Expand All @@ -29,6 +30,7 @@ export const ImageSelectorContextProvider = component$(() => {
outputFormat: 'png',
outputSizingMode: 'fixed_size',
processing: false,
downloadNameTemplate: 'Presize.io_{timestamp}',
});
useContextProvider(ImageSelectorContext, context);

Expand Down
57 changes: 52 additions & 5 deletions apps/web/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export default component$(() => {
<select
class="select select-bordered"
onChange$={(e) => {
imageSelectorContext.outputSizingMode = e.target.value as OutputSizingMode;
const target = e.target as HTMLSelectElement | null;
if (!target) {
return;
}

imageSelectorContext.outputSizingMode = target.value as OutputSizingMode;
}}
>
<option value="fixed_size">Fixed Size</option>
Expand All @@ -53,7 +58,12 @@ export default component$(() => {
class="input input-bordered w-full"
value={imageSelectorContext.outputSize.width}
onChange$={(e) => {
const value = parseInt(e.target.value);
const target = e.target as HTMLInputElement | null;
if (!target) {
return;
}

const value = parseInt(target.value);
if (!isNaN(value) && value > 0) {
imageSelectorContext.outputSize = { width: value, height: imageSelectorContext.outputSize.height };
}
Expand All @@ -69,7 +79,12 @@ export default component$(() => {
class="input input-bordered w-full"
value={imageSelectorContext.outputSize.height}
onChange$={(e) => {
const value = parseInt(e.target.value);
const target = e.target as HTMLInputElement | null;
if (!target) {
return;
}

const value = parseInt(target.value);
if (!isNaN(value) && value > 0) {
imageSelectorContext.outputSize = { width: imageSelectorContext.outputSize.width, height: value };
}
Expand All @@ -85,14 +100,40 @@ export default component$(() => {
<select
class="select select-bordered"
onChange$={(e) => {
imageSelectorContext.outputFormat = e.target.value as OutputFormat;
const target = e.target as HTMLSelectElement | null;
if (!target) {
return;
}

imageSelectorContext.outputFormat = target.value as OutputFormat;
}}
>
<option value="png">PNG</option>
<option value="jpeg">JPEG</option>
</select>
</div>
</div>
<div class="flex lg:flex-col lg:w-64 gap-2">
<div class="form-control w-full">
<label class="label">
<span class="label-text">Zip file name</span>
</label>
<input
type="text"
class="input input-bordered w-full"
value={imageSelectorContext.downloadNameTemplate}
placeholder="Presize.io_{timestamp}"
onChange$={(e) => {
const target = e.target as HTMLInputElement | null;
if (!target) {
return;
}

imageSelectorContext.downloadNameTemplate = target.value;
}}
/>
</div>
</div>
<div class="flex lg:flex-col lg:w-64 gap-2 pt-2">
<button
class="btn btn-block btn-neutral"
Expand Down Expand Up @@ -130,7 +171,13 @@ export default component$(() => {
const hiddenLink = document.createElement('a');
hiddenLink.style.display = 'none';
hiddenLink.href = zipUrl;
hiddenLink.download = `Presize.io_${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.zip`;
const formattedDate = dayjs().format('YYYY-MM-DD_HH-mm-ss');
const template = (imageSelectorContext.downloadNameTemplate || '').trim() || 'Presize.io_{timestamp}';
let downloadName = template.replaceAll('{timestamp}', formattedDate);
if (!downloadName.toLowerCase().endsWith('.zip')) {
downloadName += '.zip';
}
hiddenLink.download = downloadName;
document.body.appendChild(hiddenLink);

hiddenLink.click();
Expand Down