mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-28 09:19:37 +02:00
commit
a3f1dc7471
9 changed files with 53 additions and 17 deletions
|
@ -11,16 +11,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
let res = await fetch('/api/activity-types/types/', {
|
let res = await fetch('/activities', {
|
||||||
method: 'GET',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let data = await res.json();
|
let data = await res.json();
|
||||||
console.log('ACTIVITIES' + data);
|
console.log('ACTIVITIES' + data.activities);
|
||||||
if (data) {
|
if (data && data.activities) {
|
||||||
allActivities = data;
|
allActivities = data.activities;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
export let longitude: number | null = null;
|
export let longitude: number | null = null;
|
||||||
export let latitude: number | null = null;
|
export let latitude: number | null = null;
|
||||||
export let collection_id: number | null = null;
|
export let collection_id: string | null = null;
|
||||||
|
|
||||||
import MapMarker from '~icons/mdi/map-marker';
|
import MapMarker from '~icons/mdi/map-marker';
|
||||||
import Calendar from '~icons/mdi/calendar';
|
import Calendar from '~icons/mdi/calendar';
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
export let endDate: string | null = null;
|
export let endDate: string | null = null;
|
||||||
|
|
||||||
let newAdventure: Adventure = {
|
let newAdventure: Adventure = {
|
||||||
id: NaN,
|
id: '',
|
||||||
type: type,
|
type: type,
|
||||||
name: '',
|
name: '',
|
||||||
location: '',
|
location: '',
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
latitude: null,
|
latitude: null,
|
||||||
longitude: null,
|
longitude: null,
|
||||||
is_public: false,
|
is_public: false,
|
||||||
collection: collection_id || NaN
|
collection: collection_id || ''
|
||||||
};
|
};
|
||||||
|
|
||||||
if (longitude && latitude) {
|
if (longitude && latitude) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ export type Adventure = {
|
||||||
link?: string | null;
|
link?: string | null;
|
||||||
image?: string | null;
|
image?: string | null;
|
||||||
date?: string | null; // Assuming date is a string in 'YYYY-MM-DD' format
|
date?: string | null; // Assuming date is a string in 'YYYY-MM-DD' format
|
||||||
collection?: number | null;
|
collection?: string | null;
|
||||||
latitude: number | null;
|
latitude: number | null;
|
||||||
longitude: number | null;
|
longitude: number | null;
|
||||||
is_public: boolean;
|
is_public: boolean;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect, type Actions } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||||
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||||
|
@ -24,3 +24,20 @@ export const load = (async (event) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}) satisfies PageServerLoad;
|
}) satisfies PageServerLoad;
|
||||||
|
|
||||||
|
export const actions: Actions = {
|
||||||
|
getActivities: async (event) => {
|
||||||
|
let allActivities: string[] = [];
|
||||||
|
let res = await fetch(`${endpoint}/api/activity-types/types/`, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Cookie: `${event.cookies.get('auth')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let data = await res.json();
|
||||||
|
if (data) {
|
||||||
|
allActivities = data;
|
||||||
|
}
|
||||||
|
return { activities: allActivities };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
19
frontend/src/routes/activities/+server.ts
Normal file
19
frontend/src/routes/activities/+server.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { json } from '@sveltejs/kit';
|
||||||
|
import type { RequestHandler } from '../data/$types';
|
||||||
|
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||||
|
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||||
|
|
||||||
|
export const POST: RequestHandler = async (event) => {
|
||||||
|
let allActivities: string[] = [];
|
||||||
|
let res = await fetch(`${endpoint}/api/activity-types/types/`, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Cookie: `${event.cookies.get('auth')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let data = await res.json();
|
||||||
|
if (data) {
|
||||||
|
allActivities = data;
|
||||||
|
}
|
||||||
|
return json({ activities: allActivities });
|
||||||
|
};
|
|
@ -98,7 +98,7 @@
|
||||||
let adventureToEdit: Adventure;
|
let adventureToEdit: Adventure;
|
||||||
let isEditModalOpen: boolean = false;
|
let isEditModalOpen: boolean = false;
|
||||||
|
|
||||||
function deleteAdventure(event: CustomEvent<number>) {
|
function deleteAdventure(event: CustomEvent<string>) {
|
||||||
adventures = adventures.filter((adventure) => adventure.id !== event.detail);
|
adventures = adventures.filter((adventure) => adventure.id !== event.detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteCollection(event: CustomEvent<number>) {
|
function deleteCollection(event: CustomEvent<string>) {
|
||||||
collections = collections.filter((collection) => collection.id !== event.detail);
|
collections = collections.filter((collection) => collection.id !== event.detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
let collectionToEdit: Collection;
|
let collectionToEdit: Collection;
|
||||||
let isEditModalOpen: boolean = false;
|
let isEditModalOpen: boolean = false;
|
||||||
|
|
||||||
function deleteAdventure(event: CustomEvent<number>) {
|
function deleteAdventure(event: CustomEvent<string>) {
|
||||||
collections = collections.filter((adventure) => adventure.id !== event.detail);
|
collections = collections.filter((adventure) => adventure.id !== event.detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@
|
||||||
value="name"
|
value="name"
|
||||||
hidden
|
hidden
|
||||||
/>
|
/>
|
||||||
<button type="submit" class="btn btn-success btn-primary mt-4">Filter</button>
|
<button type="submit" class="btn btn-success btn-primary mt-4">Sort</button>
|
||||||
</form>
|
</form>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -79,7 +79,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function deleteAdventure(event: CustomEvent<number>) {
|
function deleteAdventure(event: CustomEvent<string>) {
|
||||||
adventures = adventures.filter((a) => a.id !== event.detail);
|
adventures = adventures.filter((a) => a.id !== event.detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeType(event: CustomEvent<number>) {
|
function changeType(event: CustomEvent<string>) {
|
||||||
adventures = adventures.map((adventure) => {
|
adventures = adventures.map((adventure) => {
|
||||||
if (adventure.id == event.detail) {
|
if (adventure.id == event.detail) {
|
||||||
if (adventure.type == 'visited') {
|
if (adventure.type == 'visited') {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
function deleteAdventure(event: CustomEvent<number>) {
|
function deleteAdventure(event: CustomEvent<string>) {
|
||||||
myAdventures = myAdventures.filter((adventure) => adventure.id !== event.detail);
|
myAdventures = myAdventures.filter((adventure) => adventure.id !== event.detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue