konulu-konum/src/scripts/index.ts
log101 8f61c0f99f
All checks were successful
/ Build (push) Successful in 34s
refactor: use native form post instead if ajax
2024-08-05 12:17:26 +03:00

54 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { toggleButton, validateFileInput } from "@/lib/domUtils"
import { toast } from "@/lib/utils"
export function toggleMap() {
const coordinatesText = document.getElementById("coordinates")
const mapDiv = document.getElementById("map")
mapDiv?.classList.add("border-slate-900")
coordinatesText?.classList.add("drop-shadow-2xl")
setTimeout(() => {
mapDiv?.classList.remove("border-slate-900")
coordinatesText?.classList.remove("drop-shadow-2xl")
}, 800)
}
const handleSubmit = async (e: SubmitEvent) => {
toggleButton("submit-button", "submit-button-spinner")
const locationSelected = document.getElementById(
"geolocation-input"
) as HTMLInputElement | null
if (!locationSelected) {
throw new Error("Element could not be found!")
}
if (!locationSelected.value) {
const map = document.getElementById("map")
map?.scrollIntoView({ behavior: "smooth", block: "center" })
return toggleMap()
}
const inputEl = document.getElementById(
"photo-selector"
) as HTMLInputElement | null
if (!inputEl) {
throw new Error("Element could not be found!")
}
validateFileInput(inputEl)
}
document.getElementById("sample-form")!.onsubmit = handleSubmit
document.getElementById("photo-selector")!.oninput = (ev) =>
validateFileInput(ev.target as HTMLInputElement)
const url = new URL(document.URL)
if (url.searchParams.get("error"))
toast("Konulu konum oluşturulamadı, lütfen tekrar deneyin.")