mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-28 09:19:37 +02:00
feat: Remove locations API call and implement random background image in stats view
This commit is contained in:
parent
d31b95289d
commit
00f0fc9acf
3 changed files with 12 additions and 49 deletions
|
@ -49,10 +49,3 @@ class StatsViewSet(viewsets.ViewSet):
|
||||||
'visited_country_count': visited_country_count,
|
'visited_country_count': visited_country_count,
|
||||||
'total_countries': total_countries
|
'total_countries': total_countries
|
||||||
})
|
})
|
||||||
|
|
||||||
# locations - returns a list of all of the latitude, longitude locations of all public adventrues on the server
|
|
||||||
@action(detail=False, methods=['get'], url_path='locations')
|
|
||||||
def locations(self, request):
|
|
||||||
adventures = Adventure.objects.filter(
|
|
||||||
is_public=True).values('latitude', 'longitude', 'id', 'name')
|
|
||||||
return Response(adventures)
|
|
|
@ -2,7 +2,7 @@ const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||||
import { redirect, type Actions } from '@sveltejs/kit';
|
import { redirect, type Actions } from '@sveltejs/kit';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import psl from 'psl';
|
import psl from 'psl';
|
||||||
import { themes } from '$lib';
|
import { getRandomBackground, themes } from '$lib';
|
||||||
import { fetchCSRFToken } from '$lib/index.server';
|
import { fetchCSRFToken } from '$lib/index.server';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
|
@ -12,16 +12,10 @@ export const load = (async (event) => {
|
||||||
if (event.locals.user) {
|
if (event.locals.user) {
|
||||||
return redirect(302, '/dashboard');
|
return redirect(302, '/dashboard');
|
||||||
} else {
|
} else {
|
||||||
let res = await fetch(`${serverEndpoint}/api/stats/locations/`, {
|
const background = getRandomBackground();
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let data = await res.json();
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
locations: data
|
background
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
import { DefaultMarker, MapLibre, Marker, Popup } from 'svelte-maplibre';
|
|
||||||
|
|
||||||
import MapWithPins from '$lib/assets/MapWithPins.webp';
|
import MapWithPins from '$lib/assets/MapWithPins.webp';
|
||||||
|
import type { Background } from '$lib/types.js';
|
||||||
import InformationSlabCircleOutline from '~icons/mdi/information-slab-circle-outline';
|
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
|
let background: Background = data.props?.background ?? { url: '' };
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Hero Section -->
|
<!-- Hero Section -->
|
||||||
|
@ -58,35 +58,11 @@
|
||||||
</div>
|
</div>
|
||||||
<!-- Image -->
|
<!-- Image -->
|
||||||
<div class="w-full md:w-1/2">
|
<div class="w-full md:w-1/2">
|
||||||
<p class="flex items-center text-neutral-content">
|
<img
|
||||||
<InformationSlabCircleOutline class="w-4 h-4 mr-1" />
|
src={background.url}
|
||||||
{$t('adventures.welcome_map_info')}
|
alt={background.location}
|
||||||
</p>
|
class="rounded-lg shadow-lg object-cover w-full h-full"
|
||||||
<MapLibre
|
/>
|
||||||
style="https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json"
|
|
||||||
class="flex items-center self-center justify-center aspect-[9/16] max-h-[70vh] sm:aspect-video sm:max-h-full w-10/12 rounded-lg"
|
|
||||||
standardControls
|
|
||||||
>
|
|
||||||
{#each data.props.locations as location}
|
|
||||||
{#if location.latitude && location.longitude}
|
|
||||||
<DefaultMarker
|
|
||||||
lngLat={[location.longitude, location.latitude]}
|
|
||||||
on:click={() => goto(`/locations/${location.id}`)}
|
|
||||||
>
|
|
||||||
<span class="text-xl">{location.name}</span>
|
|
||||||
<Popup openOn="click" offset={[0, -10]}>
|
|
||||||
<div class="text-lg text-black font-bold">{location.name}</div>
|
|
||||||
<button
|
|
||||||
class="btn btn-neutral btn-wide btn-sm mt-4"
|
|
||||||
on:click={() => goto(`/adventures/${location.id}`)}
|
|
||||||
>
|
|
||||||
{$t('map.view_details')}
|
|
||||||
</button>
|
|
||||||
</Popup>
|
|
||||||
</DefaultMarker>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
</MapLibre>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue