2023-07-20 04:15:12 +07:00
|
|
|
<svelte:options tag="groups-add-component" />
|
|
|
|
|
|
|
|
<script>
|
|
|
|
// Import statements
|
|
|
|
import { onMount } from 'svelte'
|
|
|
|
import { writable } from 'svelte/store';
|
2023-07-21 21:38:02 +07:00
|
|
|
import { loadLocaleContent, getData, sendData } from "/js/libraries/serverTools.js"
|
2023-07-28 21:49:29 +07:00
|
|
|
import { addMarkersEntries, translate } from "/js/libraries/mapTools.js"
|
2023-07-20 04:15:12 +07:00
|
|
|
|
|
|
|
// Import components
|
|
|
|
import "/js/components/map-component.js"
|
|
|
|
|
|
|
|
// Main code
|
|
|
|
let loaded = writable(0)
|
|
|
|
let content = writable({})
|
2023-07-28 21:49:29 +07:00
|
|
|
let entries
|
|
|
|
let entriesByCountry
|
2023-07-22 17:22:35 +07:00
|
|
|
|
|
|
|
let callback = (response) => {
|
2023-07-28 21:49:29 +07:00
|
|
|
entries = JSON.parse(response)
|
|
|
|
entriesByCountry = {}
|
|
|
|
for (let g of entries) {
|
2023-07-22 17:22:35 +07:00
|
|
|
let country = g.country
|
|
|
|
if (g.contact==null) {
|
|
|
|
g.contact = "https://discord.gg/Qk8KUk787z"
|
|
|
|
}
|
2023-07-28 21:49:29 +07:00
|
|
|
if (country in entriesByCountry) {
|
|
|
|
entriesByCountry[country].push(g)
|
2023-07-22 17:22:35 +07:00
|
|
|
}
|
|
|
|
else {
|
2023-07-28 21:49:29 +07:00
|
|
|
entriesByCountry[country] = [g]
|
2023-07-22 17:22:35 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
loaded.update((val) => {
|
|
|
|
return val + 1
|
|
|
|
})
|
|
|
|
}
|
|
|
|
getData("/assets/groups.json",callback)
|
|
|
|
|
2023-07-20 04:15:12 +07:00
|
|
|
|
2023-07-20 04:57:20 +07:00
|
|
|
let confirmationMsg
|
2023-07-20 04:15:12 +07:00
|
|
|
let addressInput
|
|
|
|
let contactInput
|
|
|
|
let addressVec
|
|
|
|
let userPinLat = 0
|
|
|
|
let userPinLng = 0
|
|
|
|
let userPin = createPin(0,0)
|
|
|
|
userPin.setOpacity(0)
|
|
|
|
|
|
|
|
let locale = loadLocaleContent(content,"groups-component",loaded)
|
|
|
|
loadLocaleContent(content,"countries",loaded)
|
|
|
|
|
|
|
|
function createPin(lat,lng) {
|
|
|
|
let markerIcon = new L.Icon({
|
|
|
|
iconUrl: '/img/common/markers/marker-black.png',
|
|
|
|
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
|
|
|
|
iconSize: [25, 41],
|
|
|
|
iconAnchor: [12, 41],
|
|
|
|
popupAnchor: [1, -34],
|
|
|
|
shadowSize: [41, 41]
|
|
|
|
})
|
|
|
|
return L.marker([lat,lng], {icon: markerIcon})
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePin(marker,lat,lng) {
|
|
|
|
let newLatLng = L.latLng(lat, lng); // Replace with the desired coordinates
|
|
|
|
marker.setLatLng(newLatLng)
|
|
|
|
}
|
|
|
|
|
2023-07-25 20:49:40 +07:00
|
|
|
function reverseGeocodeLocal(latitude, longitude) {
|
2023-07-20 04:15:12 +07:00
|
|
|
let url = `https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2`;
|
|
|
|
|
|
|
|
let callback = (response) => {
|
|
|
|
// Parse the response JSON
|
|
|
|
response = JSON.parse(response)
|
|
|
|
// Extract the address information from the response
|
|
|
|
let address = response.address
|
|
|
|
let city = address.city || address.town || address.village || address.hamlet
|
|
|
|
let state = address.state
|
|
|
|
let country = address.country
|
|
|
|
let fullAddress = country
|
|
|
|
if (state!=undefined) {
|
|
|
|
fullAddress += ", " + state
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
state = ""
|
|
|
|
}
|
|
|
|
if (city!=undefined) {
|
|
|
|
fullAddress += ", " + city
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
city = ""
|
|
|
|
}
|
|
|
|
addressInput.value = fullAddress
|
2023-07-20 17:26:26 +07:00
|
|
|
resizeInput(addressInput)
|
2023-07-25 20:49:40 +07:00
|
|
|
}
|
|
|
|
getData(url,callback)
|
|
|
|
}
|
|
|
|
|
|
|
|
function reverseGeocode(latitude, longitude) {
|
|
|
|
let url = `https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2&accept-language=en`;
|
|
|
|
|
|
|
|
let callback = (response) => {
|
|
|
|
// Parse the response JSON
|
|
|
|
response = JSON.parse(response)
|
|
|
|
// Extract the address information from the response
|
|
|
|
let address = response.address
|
|
|
|
let city = address.city || address.town || address.village || address.hamlet
|
|
|
|
let state = address.state
|
|
|
|
let country = address.country
|
|
|
|
let fullAddress = country
|
|
|
|
if (state!=undefined) {
|
|
|
|
fullAddress += ", " + state
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
state = ""
|
|
|
|
}
|
|
|
|
if (city!=undefined) {
|
|
|
|
fullAddress += ", " + city
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
city = ""
|
|
|
|
}
|
2023-07-20 04:15:12 +07:00
|
|
|
addressVec = [country,state,city]
|
|
|
|
}
|
|
|
|
getData(url,callback)
|
|
|
|
}
|
|
|
|
|
2023-07-28 21:49:29 +07:00
|
|
|
function addGroupPinContent(g,content,locale) {
|
|
|
|
let coordinates
|
|
|
|
let text = "<b>"+content["Group"]+"</b><br>"
|
|
|
|
for (let field of ["location","members","contact"]) {
|
|
|
|
let fieldText = content[field] + ": "
|
|
|
|
if (field=="contact") {
|
|
|
|
text += fieldText + "<a href='" + g.contact + "' target='_blank' rel=noreferrer>" + g.contact + "</a>"
|
|
|
|
}
|
|
|
|
else if (field=="location") {
|
|
|
|
let location = [g.country,g.state,g.town].filter(x => x!=null && x!=undefined)
|
|
|
|
let locationString
|
|
|
|
if (locale=="en") {
|
|
|
|
locationString = location.map(x => x).join(", ")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
locationString = location.map(x => translate(content, x)).join(", ")
|
|
|
|
}
|
|
|
|
text += fieldText + locationString + "<br>"
|
|
|
|
coordinates = [g.latitude,g.longitude]
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
text += fieldText + g[field] + "<br>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {text,coordinates}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function mapCallback(createMap,content,locale) {
|
2023-07-20 04:15:12 +07:00
|
|
|
let map = createMap([22, 0],2)
|
2023-07-28 21:49:29 +07:00
|
|
|
addMarkersEntries(entries,entriesByCountry,map,content,locale,addGroupPinContent,"green")
|
2023-07-20 04:15:12 +07:00
|
|
|
|
|
|
|
userPin.addTo(map)
|
|
|
|
map.on('click', function(event) {
|
|
|
|
let lat = event.latlng.lat;
|
|
|
|
let lng = event.latlng.lng;
|
|
|
|
userPinLat = lat
|
|
|
|
userPinLng = lng
|
|
|
|
updatePin(userPin,lat,lng)
|
|
|
|
userPin.setOpacity(1)
|
2023-07-25 20:49:40 +07:00
|
|
|
reverseGeocodeLocal(lat, lng)
|
2023-07-20 04:15:12 +07:00
|
|
|
reverseGeocode(lat, lng)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-20 04:57:20 +07:00
|
|
|
function updateConfirmationMsg(response) {
|
|
|
|
if (response!==false) {
|
|
|
|
|
|
|
|
confirmationMsg.innerHTML = "You have been added to our database! Now go to our Discord to verify yourself."
|
|
|
|
confirmationMsg.style.color = "green"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
confirmationMsg.innerHTML = "Something went wrong."
|
|
|
|
confirmationMsg.style.color = "red"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-07-20 04:15:12 +07:00
|
|
|
function submitLocation() {
|
|
|
|
if (addressVec!=undefined) {
|
2023-07-21 21:38:02 +07:00
|
|
|
let data = {
|
|
|
|
country: addressVec[0],
|
|
|
|
state: addressVec[1],
|
|
|
|
town: addressVec[2],
|
|
|
|
latitude: userPinLat,
|
|
|
|
longitude: userPinLng,
|
2023-07-22 17:22:35 +07:00
|
|
|
contact: contactInput.value
|
2023-07-21 21:38:02 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.state=="") {
|
|
|
|
data.state = null
|
|
|
|
}
|
|
|
|
if (data.town=="") {
|
|
|
|
data.town = null
|
|
|
|
}
|
|
|
|
if (data.contact=="") {
|
|
|
|
data.contact = null
|
|
|
|
}
|
2023-07-20 04:15:12 +07:00
|
|
|
let url = "/" + locale + "/groups-add-post/"
|
2023-07-21 21:38:02 +07:00
|
|
|
sendData(url,data,updateConfirmationMsg)
|
2023-07-20 04:15:12 +07:00
|
|
|
}
|
2023-07-20 17:26:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
function resizeInput(el) {
|
|
|
|
el.nextElementSibling.innerHTML = el.value
|
2023-07-20 04:15:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#key $loaded}
|
2023-07-22 17:22:35 +07:00
|
|
|
{#if $loaded==3}
|
2023-07-20 04:15:12 +07:00
|
|
|
<div id="container">
|
|
|
|
<!--<img src="img/crowd.png" id="crowd" alt="crowd">-->
|
|
|
|
<div id="text-container">
|
|
|
|
<h1>Add a Group</h1>
|
|
|
|
<img id="groups-img" src="/img/common/groups.svg" alt="groups">
|
2023-07-20 04:44:44 +07:00
|
|
|
<p class="description">If there are no groups in your town with whom you can organize then do the following:</p>
|
2023-07-20 04:15:12 +07:00
|
|
|
<ol>
|
2023-07-20 04:44:44 +07:00
|
|
|
<li>Click on the map to show us where you are located;</li>
|
2023-07-30 17:04:15 +07:00
|
|
|
<li>Add a way to contact you (an invite link or an email, not a phone number) or leave blank for a pin to point to our discord;</li>
|
2023-07-20 04:44:44 +07:00
|
|
|
<li>Press "Submit" to add yourself to our map;</li>
|
|
|
|
<li>Verify yourself by having a chat with us at our Discord server to show on the map;</li>
|
2023-07-20 04:15:12 +07:00
|
|
|
</ol>
|
2023-07-20 17:26:26 +07:00
|
|
|
<div id="address-input-wrapper" class="input-label-wrapper">
|
|
|
|
<label for="address-input">Location: </label>
|
|
|
|
<div class="input-wrapper">
|
|
|
|
<input bind:this={addressInput} on:input={() => resizeInput(addressInput)} id="address-input" type="text" readonly>
|
|
|
|
<div class="ghost-input"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="input-label-wrapper">
|
|
|
|
<label for="contact-input">Contact: </label>
|
|
|
|
<div class="input-wrapper">
|
|
|
|
<input bind:this={contactInput} on:input={() => resizeInput(contactInput)} id="contact-input" type="text">
|
|
|
|
<div class="ghost-input"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-20 04:15:12 +07:00
|
|
|
<button id="submit-button" on:click={submitLocation}>Submit</button>
|
2023-07-20 04:57:20 +07:00
|
|
|
<p id="confirmation-msg" bind:this={confirmationMsg}></p>
|
2023-07-28 21:49:29 +07:00
|
|
|
<map-component id="map" callback={(createMap) => mapCallback(createMap,$content,locale)}></map-component>
|
2023-07-20 04:15:12 +07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{/key}
|
|
|
|
|
|
|
|
<style>
|
|
|
|
@import '/css/common.css';
|
|
|
|
|
2023-07-20 04:57:20 +07:00
|
|
|
#confirmation-msg {
|
|
|
|
margin-top: 0.5rem;
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
}
|
|
|
|
|
2023-07-20 04:15:12 +07:00
|
|
|
ol li {
|
|
|
|
margin-left: 3rem;
|
2023-07-20 04:44:44 +07:00
|
|
|
margin-bottom: 0.5rem;
|
2023-07-20 04:15:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
label {
|
|
|
|
display: inline-block;
|
|
|
|
font-family: var(--serif,serif);
|
|
|
|
font-size: 1.15rem;
|
|
|
|
line-height: 160%;
|
|
|
|
color: #222222;
|
|
|
|
width: 5.5rem;
|
|
|
|
}
|
|
|
|
|
2023-07-20 17:26:26 +07:00
|
|
|
input, .ghost-input {
|
2023-07-20 04:15:12 +07:00
|
|
|
font-size: 1.15rem;
|
|
|
|
font-family: var(--serif,serif);
|
2023-07-20 17:26:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
input {
|
2023-07-20 04:15:12 +07:00
|
|
|
height: 2.5rem;
|
2023-07-20 17:26:26 +07:00
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
#address-input, #contact-input {
|
|
|
|
width: 100%;
|
2023-07-20 04:15:12 +07:00
|
|
|
}
|
|
|
|
|
2023-07-20 17:26:26 +07:00
|
|
|
#address-input-wrapper {
|
2023-07-20 04:15:12 +07:00
|
|
|
margin-top: 2rem;
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
}
|
|
|
|
|
2023-07-20 17:26:26 +07:00
|
|
|
.ghost-input {
|
|
|
|
display: block;
|
|
|
|
visibility: hidden;
|
|
|
|
height: 0;
|
|
|
|
|
|
|
|
padding-left: 0.5rem;
|
|
|
|
padding-right: 0.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input-wrapper {
|
|
|
|
display: inline-block;
|
|
|
|
max-width: calc(100% - 5.5rem);
|
|
|
|
min-width: min(20rem, calc(100% - 5.5rem));
|
|
|
|
height: 2.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input-label-wrapper {
|
|
|
|
display: flex;
|
|
|
|
justify-content: start;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input-label-wrapper label {
|
|
|
|
position: relative;
|
|
|
|
top: 0.3rem;
|
2023-07-20 04:15:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
.description {
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
#submit-button {
|
|
|
|
display: block;
|
2023-07-20 04:57:20 +07:00
|
|
|
margin: auto;
|
2023-07-20 04:15:12 +07:00
|
|
|
margin-top: 2rem;
|
|
|
|
padding: 1rem 2rem;
|
|
|
|
font-size: 1.4rem;
|
|
|
|
font-family: var(--sans-serif,sans-serif);
|
|
|
|
border: 0rem solid black;
|
|
|
|
border-radius: 0.5rem;
|
|
|
|
background: #cb1816;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
#add-prompt {
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
#groups-img {
|
|
|
|
position: absolute;
|
|
|
|
width: 14rem;
|
|
|
|
left: 50%;
|
|
|
|
transform: translate(-50%);
|
|
|
|
z-index: 0;
|
|
|
|
opacity: 0.2;
|
|
|
|
}
|
|
|
|
|
|
|
|
#text-container>:nth-child(3) {
|
|
|
|
margin-top: 8rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.country-name {
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.country-block {
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.location-info {
|
|
|
|
margin-bottom: 0.75rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.location-info p {
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
a {
|
|
|
|
color: #DD1C1A;
|
|
|
|
}
|
|
|
|
|
|
|
|
#map {
|
|
|
|
--height: 30rem;
|
|
|
|
--width: 100%;
|
2023-07-20 04:57:20 +07:00
|
|
|
--margin-top: 2rem;
|
2023-07-20 04:15:12 +07:00
|
|
|
--margin-bottom: 0.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
#text-container {
|
|
|
|
position: relative;
|
|
|
|
max-width: calc(100vw - 4rem);
|
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
font-size: 2.2rem;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
h3 {
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
#container {
|
|
|
|
margin: auto;
|
|
|
|
max-width: 800px;
|
|
|
|
margin-top: 1rem;
|
|
|
|
margin-bottom: 4rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
#container p {
|
|
|
|
text-align: justify;
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|