mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Upload svgs for room icon
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
import StickerSmileSquare from "@assets/icons/sticker-smile-square.svg?dataurl"
|
import StickerSmileSquare from "@assets/icons/sticker-smile-square.svg?dataurl"
|
||||||
import Hashtag from "@assets/icons/hashtag.svg?dataurl"
|
import Hashtag from "@assets/icons/hashtag.svg?dataurl"
|
||||||
import UploadMinimalistic from "@assets/icons/upload-minimalistic.svg?dataurl"
|
import UploadMinimalistic from "@assets/icons/upload-minimalistic.svg?dataurl"
|
||||||
import {preventDefault, compressFile} from "@lib/html"
|
import {preventDefault} from "@lib/html"
|
||||||
import FieldInline from "@lib/components/FieldInline.svelte"
|
import FieldInline from "@lib/components/FieldInline.svelte"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import ImageIcon from "@lib/components/ImageIcon.svelte"
|
import ImageIcon from "@lib/components/ImageIcon.svelte"
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
const room = $state.snapshot(values)
|
const room = $state.snapshot(values)
|
||||||
|
|
||||||
if (imageFile) {
|
if (imageFile) {
|
||||||
const {error, result} = await uploadFile(imageFile)
|
const {error, result} = await uploadFile(imageFile, {maxWidth: 128, maxHeight: 128})
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return pushToast({theme: "error", message: error})
|
return pushToast({theme: "error", message: error})
|
||||||
@@ -38,8 +38,6 @@
|
|||||||
|
|
||||||
room.picture = result.url
|
room.picture = result.url
|
||||||
room.pictureMeta = result.tags
|
room.pictureMeta = result.tags
|
||||||
} else if (selectedIcon) {
|
|
||||||
room.picture = selectedIcon
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const createMessage = await waitForThunkError(createRoom(url, room))
|
const createMessage = await waitForThunkError(createRoom(url, room))
|
||||||
@@ -76,29 +74,34 @@
|
|||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
let imageFile = $state<File | undefined>()
|
let imageFile = $state<File | undefined>()
|
||||||
let imagePreview = $state(initialValues.picture)
|
let imagePreview = $state(initialValues.picture)
|
||||||
let selectedIcon = $state<string | undefined>()
|
|
||||||
|
|
||||||
const handleImageUpload = async (event: Event) => {
|
const handleImageUpload = async (event: Event) => {
|
||||||
const file = (event.target as HTMLInputElement).files?.[0]
|
const file = (event.target as HTMLInputElement).files?.[0]
|
||||||
|
|
||||||
if (file && file.type.startsWith("image/")) {
|
if (file && file.type.startsWith("image/")) {
|
||||||
selectedIcon = undefined
|
|
||||||
imageFile = await compressFile(file, {maxWidth: 64, maxHeight: 64})
|
|
||||||
|
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
|
|
||||||
reader.onload = e => {
|
reader.onload = e => {
|
||||||
|
imageFile = file
|
||||||
imagePreview = e.target?.result as string
|
imagePreview = e.target?.result as string
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.readAsDataURL(imageFile)
|
reader.readAsDataURL(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleIconSelect = (iconUrl: string) => {
|
const handleIconSelect = (iconUrl: string) => {
|
||||||
imageFile = undefined
|
imagePreview = iconUrl
|
||||||
imagePreview = undefined
|
|
||||||
selectedIcon = iconUrl
|
const parts = iconUrl.split(",")
|
||||||
|
const imageData = atob(parts[1])
|
||||||
|
const result = new Uint8Array(imageData.length)
|
||||||
|
|
||||||
|
for (let n = 0; n < imageData.length; n++) {
|
||||||
|
result[n] = imageData.charCodeAt(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
imageFile = new File([result], `icon.svg`, {type: "image/svg+xml"})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -116,11 +119,6 @@
|
|||||||
<span class="text-sm opacity-75">Selected:</span>
|
<span class="text-sm opacity-75">Selected:</span>
|
||||||
<ImageIcon src={imagePreview} alt="Room icon preview" />
|
<ImageIcon src={imagePreview} alt="Room icon preview" />
|
||||||
</div>
|
</div>
|
||||||
{:else if selectedIcon}
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<span class="text-sm opacity-75">Selected:</span>
|
|
||||||
<Icon icon={selectedIcon} class="h-8 w-8" />
|
|
||||||
</div>
|
|
||||||
{:else}
|
{:else}
|
||||||
<span class="text-sm opacity-75">No icon selected</span>
|
<span class="text-sm opacity-75">No icon selected</span>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -147,8 +145,6 @@
|
|||||||
<label class="input input-bordered flex w-full items-center gap-2">
|
<label class="input input-bordered flex w-full items-center gap-2">
|
||||||
{#if imagePreview}
|
{#if imagePreview}
|
||||||
<ImageIcon src={imagePreview} alt="Room icon preview" />
|
<ImageIcon src={imagePreview} alt="Room icon preview" />
|
||||||
{:else if selectedIcon}
|
|
||||||
<Icon icon={selectedIcon} class="h-8 w-8" />
|
|
||||||
{:else}
|
{:else}
|
||||||
<Icon icon={Hashtag} />
|
<Icon icon={Hashtag} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $room.picture}
|
{#if $room.picture}
|
||||||
<ImageIcon src={$room.picture} {size} alt="Room icon" />
|
<ImageIcon src={$room.picture} {size} alt="Room icon" class="rounded-lg" />
|
||||||
{:else}
|
{:else}
|
||||||
<Icon icon={Hashtag} {size} />
|
<Icon icon={Hashtag} {size} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -57,8 +57,6 @@
|
|||||||
if (imageFile) {
|
if (imageFile) {
|
||||||
const {error, result} = await uploadFile(imageFile, {maxWidth: 128, maxHeight: 128})
|
const {error, result} = await uploadFile(imageFile, {maxWidth: 128, maxHeight: 128})
|
||||||
|
|
||||||
console.log(imageFile, result)
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return pushToast({theme: "error", message: error})
|
return pushToast({theme: "error", message: error})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user