diff --git a/backend/server/adventures/migrations/0011_adventure_updated_at.py b/backend/server/adventures/migrations/0011_adventure_updated_at.py new file mode 100644 index 00000000..d04e34a4 --- /dev/null +++ b/backend/server/adventures/migrations/0011_adventure_updated_at.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.6 on 2024-07-19 12:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('adventures', '0010_adventure_created_at_collection_created_at'), + ] + + operations = [ + migrations.AddField( + model_name='adventure', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/backend/server/adventures/models.py b/backend/server/adventures/models.py index 14a1da86..3ff173a4 100644 --- a/backend/server/adventures/models.py +++ b/backend/server/adventures/models.py @@ -36,6 +36,7 @@ class Adventure(models.Model): latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True) collection = models.ForeignKey('Collection', on_delete=models.CASCADE, blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) def clean(self): if self.collection: diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py index 917fd534..b9fcb301 100644 --- a/backend/server/adventures/views.py +++ b/backend/server/adventures/views.py @@ -31,11 +31,11 @@ class AdventureViewSet(viewsets.ModelViewSet): pagination_class = StandardResultsSetPagination def apply_sorting(self, queryset): - order_by = self.request.query_params.get('order_by', 'created_at') + order_by = self.request.query_params.get('order_by', 'updated_at') order_direction = self.request.query_params.get('order_direction', 'asc') include_collections = self.request.query_params.get('include_collections', 'true') - valid_order_by = ['name', 'type', 'date', 'rating', 'created_at'] + valid_order_by = ['name', 'type', 'date', 'rating', 'updated_at'] if order_by not in valid_order_by: order_by = 'name' @@ -52,12 +52,12 @@ def apply_sorting(self, queryset): if order_direction == 'desc': ordering = f'-{ordering}' - # reverse ordering for created_at field - if order_by == 'created_at': + # reverse ordering for updated_at field + if order_by == 'updated_at': if order_direction == 'asc': - ordering = '-created_at' + ordering = '-updated_at' else: - ordering = 'created_at' + ordering = 'updated_at' print(f"Ordering by: {ordering}") # For debugging diff --git a/frontend/src/lib/components/ActivityComplete.svelte b/frontend/src/lib/components/ActivityComplete.svelte index 6d76abf7..773f7719 100644 --- a/frontend/src/lib/components/ActivityComplete.svelte +++ b/frontend/src/lib/components/ActivityComplete.svelte @@ -81,7 +81,11 @@ {#each activities as activity}
  • {activity} -
  • diff --git a/frontend/src/lib/components/AdventureCard.svelte b/frontend/src/lib/components/AdventureCard.svelte index 48242085..4afacb72 100644 --- a/frontend/src/lib/components/AdventureCard.svelte +++ b/frontend/src/lib/components/AdventureCard.svelte @@ -1,7 +1,7 @@ {#if isPointModalOpen} - (isPointModalOpen = false)} on:submit={setLongLat} /> + (isPointModalOpen = false)} + on:submit={setLongLat} + /> {/if} {#if isImageFetcherOpen} - (isImageFetcherOpen = false)} /> + (isImageFetcherOpen = false)} + /> {/if} diff --git a/frontend/src/lib/components/PointSelectionModal.svelte b/frontend/src/lib/components/PointSelectionModal.svelte index e9e89d2e..eb44a9e9 100644 --- a/frontend/src/lib/components/PointSelectionModal.svelte +++ b/frontend/src/lib/components/PointSelectionModal.svelte @@ -10,7 +10,11 @@ let markers: Point[] = []; - let query: string = ''; + export let query: string | null = null; + + if (query) { + geocode(); + } export let longitude: number | null = null; export let latitude: number | null = null; @@ -43,8 +47,10 @@ let places: OpenStreetMapPlace[] = []; - async function geocode(e: Event) { - e.preventDefault(); + async function geocode(e: Event | null) { + if (e) { + e.preventDefault(); + } if (!query) { alert('Please enter a location'); return; diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index 978f0f75..d0dbdf52 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -25,7 +25,8 @@ export type Adventure = { latitude: number | null; longitude: number | null; is_public: boolean; - created_at?: string; + created_at?: string | null; + updated_at?: string | null; }; export type Country = { diff --git a/frontend/src/routes/adventures/+page.svelte b/frontend/src/routes/adventures/+page.svelte index 4eb087e3..d5d598e0 100644 --- a/frontend/src/routes/adventures/+page.svelte +++ b/frontend/src/routes/adventures/+page.svelte @@ -181,56 +181,19 @@ > {sidebarOpen ? 'Close Filters' : 'Open Filters'} - {#if currentView == 'cards'} -
    - {#each adventures as adventure} - - {/each} -
    - {/if} - {#if currentView == 'table'} - - - - - - - - - - - - {#each adventures as adventure} - - - - - - - - {/each} - -
    NameDateRatingTypeActions
    {adventure.name}{adventure.date}{adventure.rating}{adventure.type} - - -
    - {/if} + +
    + {#each adventures as adventure} + + {/each} +
    +
    {#if next || previous}
    @@ -253,10 +216,11 @@
    +
    diff --git a/frontend/src/routes/collections/+page.svelte b/frontend/src/routes/collections/+page.svelte index 113e7611..4371a5c9 100644 --- a/frontend/src/routes/collections/+page.svelte +++ b/frontend/src/routes/collections/+page.svelte @@ -167,7 +167,7 @@

    My Collections

    This search returned {count} results.

    {#if collections.length === 0} - + {/if}