Skip to content

Commit

Permalink
use svelte preventdefault handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed Dec 10, 2023
1 parent ca33bb3 commit 8db4524
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 0 additions & 4 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,3 @@ export type Theme = 'light' | 'dark';
export type DonationType = 'On-chain' | 'Lightning';

export type DropdownLink = { url: string; external?: boolean; icon: string; title: string };

export type SubmitForm = SubmitEvent & {
currentTarget: EventTarget & HTMLFormElement;
};
9 changes: 5 additions & 4 deletions src/routes/add-location/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
} from '$lib/comp';
import { attribution, changeDefaultIcons, geolocate, toggleMapButtons } from '$lib/map/setup';
import { areaError, areas, socials, theme } from '$lib/store';
import type { SubmitForm } from '$lib/types';
import { detectTheme, errToast } from '$lib/utils';
// @ts-expect-error
import rewind from '@mapbox/geojson-rewind';
Expand Down Expand Up @@ -87,8 +86,7 @@
$: latFixed = lat && lat.toFixed(5);
$: longFixed = long && long.toFixed(5);
const submitForm = (e: SubmitForm) => {
e.preventDefault();
const submitForm = () => {
if (!selected) {
noLocationSelected = true;
errToast('Please select a location...');
Expand Down Expand Up @@ -384,7 +382,10 @@
/>
</p>

<form on:submit={submitForm} class="w-full space-y-5 text-primary dark:text-white">
<form
on:submit|preventDefault={submitForm}
class="w-full space-y-5 text-primary dark:text-white"
>
<div>
<label for="name" class="mb-2 block font-semibold">Merchant Name</label>
<input
Expand Down
9 changes: 5 additions & 4 deletions src/routes/communities/add/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
PrimaryButton
} from '$lib/comp';
import { theme } from '$lib/store';
import type { SubmitForm } from '$lib/types';
import { detectTheme, errToast, successToast, warningToast } from '$lib/utils';
import axios from 'axios';
import { onMount } from 'svelte';
Expand Down Expand Up @@ -86,8 +85,7 @@
successToast('Location selected!');
};
const submitForm = (e: SubmitForm) => {
e.preventDefault();
const submitForm = () => {
if (!selected) {
noLocationSelected = true;
errToast('Please select a location...');
Expand Down Expand Up @@ -178,7 +176,10 @@
</ul>
</div>

<form on:submit={submitForm} class="w-full space-y-5 text-primary dark:text-white">
<form
on:submit|preventDefault={submitForm}
class="w-full space-y-5 text-primary dark:text-white"
>
<div class="space-y-2">
<label for="location-picker" class="block font-semibold">Select Location</label>
<p class="text-sm">Search for an area and select an option from the results.</p>
Expand Down
10 changes: 6 additions & 4 deletions src/routes/verify-location/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
toggleMapButtons
} from '$lib/map/setup';
import { elementError, elements, theme } from '$lib/store';
import type { DomEventType, Element, Leaflet, SubmitForm } from '$lib/types';
import type { DomEventType, Element, Leaflet } from '$lib/types';
import { detectTheme, errToast } from '$lib/utils';
import axios from 'axios';
import type { Map, TileLayer } from 'leaflet';
Expand Down Expand Up @@ -212,8 +212,7 @@
let submitting = false;
let submissionIssueNumber: number;
const submitForm = (e: SubmitForm) => {
e.preventDefault();
const submitForm = () => {
if (!selected) {
noLocationSelected = true;
errToast('Please select a location...');
Expand Down Expand Up @@ -361,7 +360,10 @@
/>
</p>

<form on:submit={submitForm} class="w-full space-y-5 text-primary dark:text-white">
<form
on:submit|preventDefault={submitForm}
class="w-full space-y-5 text-primary dark:text-white"
>
<div>
<div class={showMap ? 'block' : 'hidden'}>
<label for="location-picker" class="mb-2 block font-semibold">Select Location</label>
Expand Down

0 comments on commit 8db4524

Please sign in to comment.