site-libsoc/Server/app/svelte/src/groups-component.svelte

171 lines
4.4 KiB
Svelte
Raw Normal View History

2023-06-24 04:39:41 +07:00
<svelte:options tag="groups-component" />
<script>
// Import statements
import { onMount } from 'svelte'
2023-07-03 03:07:45 +07:00
import { writable } from 'svelte/store';
2023-07-28 21:49:29 +07:00
import { loadLocaleContent, getData} from "/js/libraries/serverTools.js"
import { addMarkersEntries, translate } from "/js/libraries/mapTools.js"
import { addGroupPinContent } from "/js/mapFuncs.js"
2023-06-24 04:39:41 +07:00
// Import components
2023-06-24 20:44:16 +07:00
import "/js/components/map-component.js"
2023-06-24 04:39:41 +07:00
// Main code
2023-07-13 18:32:49 +07:00
let loaded = writable(0)
2023-07-03 03:07:45 +07:00
let content = writable({})
2023-07-28 21:49:29 +07:00
let entries
let entriesByCountry
2023-07-03 03:07:45 +07:00
let locale = loadLocaleContent(content,"groups-component",loaded)
2023-07-13 18:32:49 +07:00
loadLocaleContent(content,"countries",loaded)
2023-07-03 03:07:45 +07:00
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-28 21:49:29 +07:00
function mapCallback(createMap,content,locale) {
2023-07-10 21:42:33 +07:00
let map = createMap([22, 0],2)
2023-08-01 20:59:32 +07:00
let options = {
enableCountryGrouping: true,
}
addMarkersEntries(entries,entriesByCountry,map,content,locale,addGroupPinContent,"green",options)
}
2023-07-21 21:38:02 +07:00
function getCountry(x) {
return locale=="en" ? x : translate($content,x)
}
2023-07-22 17:22:35 +07:00
function getAddress(g) {
let location = [g.country,g.state,g.town].filter(x => x!=null)
return location.map(x => locale=="en" ? x : translate($content,x)).join(", ")
2023-06-24 20:44:16 +07:00
}
2023-07-21 21:38:02 +07:00
2023-06-24 04:39:41 +07:00
onMount(() => {
2023-06-24 04:39:41 +07:00
})
</script>
2023-07-13 18:32:49 +07:00
{#key $loaded}
2023-07-22 17:22:35 +07:00
{#if $loaded==3}
2023-07-03 03:07:45 +07:00
<div id="container">
<!--<img src="img/crowd.png" id="crowd" alt="crowd">-->
<div id="text-container">
2023-07-15 02:27:11 +07:00
<h1>{$content.groups}</h1>
2023-07-03 03:07:45 +07:00
<img id="groups-img" src="/img/common/groups.svg" alt="groups">
2023-07-16 20:56:28 +07:00
<p class="description">{$content.p1}</p>
2023-07-03 03:07:45 +07:00
<h3>{$content.subheading1}</h3>
2023-07-28 21:49:29 +07:00
<map-component id="map" callback={(createMap) => mapCallback(createMap,$content,locale)}></map-component>
2023-07-16 20:56:28 +07:00
<p id="add-prompt">{$content["map-prompt"]}</p>
2023-07-28 21:49:29 +07:00
{#each Object.entries(entriesByCountry) as [name,entries]}
<h4 class="country-name">{getCountry(name)}</h4>
2023-07-13 18:32:49 +07:00
<div class="country-block">
2023-07-28 21:49:29 +07:00
{#each entries as entry}
2023-07-13 18:32:49 +07:00
<div class="location-info">
2023-07-28 21:49:29 +07:00
<p><b>{$content.location}: </b>{getAddress(entry)}</p>
<p><b>{$content.members}: </b>{entry.members}</p>
<p><b>{$content.contact}: </b><a href={entry.contact} target=;_blank; rel=noreferrer>{entry.contact}</a></p>
2023-07-13 18:32:49 +07:00
</div>
{/each}
2023-07-03 03:07:45 +07:00
</div>
{/each}
2023-06-24 20:44:16 +07:00
</div>
2023-07-03 03:07:45 +07:00
</div>
{/if}
{/key}
2023-06-24 04:39:41 +07:00
<style>
@import '/css/common.css';
2023-07-16 20:56:28 +07:00
.description {
margin-bottom: 1rem;
}
#add-prompt {
margin-bottom: 2rem;
}
2023-06-25 02:29:07 +07:00
#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;
}
2023-07-13 18:32:49 +07:00
.country-name {
margin-bottom: 0.5rem;
}
.country-block {
2023-06-24 20:44:16 +07:00
margin-bottom: 2rem;
}
2023-06-26 03:22:27 +07:00
.location-info {
2023-07-13 18:32:49 +07:00
margin-bottom: 0.75rem;
2023-06-26 03:22:27 +07:00
}
2023-06-24 20:44:16 +07:00
.location-info p {
2023-06-26 03:22:27 +07:00
margin-bottom: 0;
2023-06-24 20:44:16 +07:00
}
a {
color: #DD1C1A;
}
#map {
--height: 30rem;
--width: 100%;
2023-07-18 02:05:43 +07:00
--margin-bottom: 0.5rem;
2023-06-24 20:44:16 +07:00
}
#text-container {
2023-06-25 02:29:07 +07:00
position: relative;
2023-06-24 20:44:16 +07:00
max-width: calc(100vw - 4rem);
margin: auto;
}
h1 {
margin-bottom: 1rem;
2023-06-28 18:00:41 +07:00
font-size: 2.2rem;
2023-06-24 20:44:16 +07:00
text-align: center;
}
h3 {
margin-bottom: 1rem;
}
#container {
margin: auto;
2023-07-03 03:07:45 +07:00
max-width: 800px;
2023-06-24 20:44:16 +07:00
margin-top: 1rem;
margin-bottom: 4rem;
}
#container p {
text-align: justify;
}
2023-06-24 04:39:41 +07:00
</style>