mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
format: run prettify
This commit is contained in:
@@ -1,23 +1,31 @@
|
||||
import type { LoadedCustomTheme } from '@/types/CustomThemes';
|
||||
import type { LoadedCustomTheme } from "@/types/CustomThemes";
|
||||
|
||||
export function generateImageId(): string {
|
||||
return Math.random().toString(36).substr(2, 9);
|
||||
}
|
||||
|
||||
export function handleImageUpload(event: Event, theme: LoadedCustomTheme): Promise<LoadedCustomTheme> | LoadedCustomTheme {
|
||||
export function handleImageUpload(
|
||||
event: Event,
|
||||
theme: LoadedCustomTheme,
|
||||
): Promise<LoadedCustomTheme> | LoadedCustomTheme {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
input.value = "";
|
||||
if (file) {
|
||||
return new Promise((resolve) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = async () => {
|
||||
const imageBlob = await fetch(reader.result as string).then(res => res.blob());
|
||||
const imageBlob = await fetch(reader.result as string).then((res) =>
|
||||
res.blob(),
|
||||
);
|
||||
const imageId = generateImageId();
|
||||
const variableName = `custom-image-${theme.CustomImages.length}`;
|
||||
resolve({
|
||||
...theme,
|
||||
CustomImages: [...theme.CustomImages, { id: imageId, blob: imageBlob, variableName, url: null }],
|
||||
CustomImages: [
|
||||
...theme.CustomImages,
|
||||
{ id: imageId, blob: imageBlob, variableName, url: null },
|
||||
],
|
||||
});
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
@@ -26,35 +34,47 @@ export function handleImageUpload(event: Event, theme: LoadedCustomTheme): Promi
|
||||
return theme;
|
||||
}
|
||||
|
||||
export function handleRemoveImage(imageId: string, theme: LoadedCustomTheme): LoadedCustomTheme {
|
||||
export function handleRemoveImage(
|
||||
imageId: string,
|
||||
theme: LoadedCustomTheme,
|
||||
): LoadedCustomTheme {
|
||||
return {
|
||||
...theme,
|
||||
CustomImages: theme.CustomImages.filter((image) => image.id !== imageId),
|
||||
} as LoadedCustomTheme;
|
||||
}
|
||||
|
||||
export function handleImageVariableChange(imageId: string, variableName: string, theme: LoadedCustomTheme): LoadedCustomTheme {
|
||||
export function handleImageVariableChange(
|
||||
imageId: string,
|
||||
variableName: string,
|
||||
theme: LoadedCustomTheme,
|
||||
): LoadedCustomTheme {
|
||||
return {
|
||||
...theme,
|
||||
CustomImages: theme.CustomImages.map((image) =>
|
||||
image.id === imageId ? { ...image, variableName } : image
|
||||
image.id === imageId ? { ...image, variableName } : image,
|
||||
),
|
||||
} as LoadedCustomTheme;
|
||||
}
|
||||
|
||||
export function handleCoverImageUpload(event: Event, theme: LoadedCustomTheme): Promise<LoadedCustomTheme> {
|
||||
export function handleCoverImageUpload(
|
||||
event: Event,
|
||||
theme: LoadedCustomTheme,
|
||||
): Promise<LoadedCustomTheme> {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
input.value = "";
|
||||
if (file) {
|
||||
return new Promise((resolve) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = async () => {
|
||||
const imageBlob = await fetch(reader.result as string).then(res => res.blob());
|
||||
const imageBlob = await fetch(reader.result as string).then((res) =>
|
||||
res.blob(),
|
||||
);
|
||||
resolve({ ...theme, coverImage: imageBlob });
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(theme);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user