Skip to content

Commit

Permalink
Fix general category handling
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorley15 committed Nov 26, 2024
1 parent ce0b82a commit adf45ff
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 126 deletions.
13 changes: 11 additions & 2 deletions backend/server/adventures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ def save(self, force_insert: bool = False, force_update: bool = False, using: st
if force_insert and force_update:
raise ValueError("Cannot force both insert and updating in model saving.")
if not self.category:
self.category = Category.objects.get_or_create(user_id=self.user_id, name='general', display_name='General', icon='🌍')[0]
category, created = Category.objects.get_or_create(
user_id=self.user_id,
name='general',
defaults={
'display_name': 'General',
'icon': '🌍'
}
)
self.category = category

return super().save(force_insert, force_update, using, update_fields)

def __str__(self):
Expand Down Expand Up @@ -273,4 +282,4 @@ def clean(self) -> None:


def __str__(self):
return self.name
return self.name + ' - ' + self.display_name + ' - ' + self.icon
1 change: 1 addition & 0 deletions backend/server/adventures/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def get_is_visited(self, obj):
def create(self, validated_data):
visits_data = validated_data.pop('visits', [])
category_data = validated_data.pop('category', None)
print(category_data)
adventure = Adventure.objects.create(**validated_data)
for visit_data in visits_data:
Visit.objects.create(adventure=adventure, **visit_data)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/AdventureCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
</div>
<div>
<div class="badge badge-primary">
{`${adventure.category.display_name} ${adventure.category.icon}`}
{adventure.category?.display_name + ' ' + adventure.category?.icon}
</div>
<div class="badge badge-success">
{adventure.is_visited ? $t('adventures.visited') : $t('adventures.planned')}
Expand Down
20 changes: 3 additions & 17 deletions frontend/src/lib/components/CategoryDropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
selectCategory(new_category);
}
// function removeCategory(categoryName: string) {
// categories = categories.filter((category) => category.name !== categoryName);
// if (selected_category && selected_category.name === categoryName) {
// selected_category = null;
// }
// }
// Close dropdown when clicking outside
let dropdownRef: HTMLDivElement;
Expand All @@ -59,7 +52,7 @@
<button type="button" class="btn btn-outline w-full text-left" on:click={toggleDropdown}>
{selected_category && selected_category.name
? selected_category.display_name + ' ' + selected_category.icon
: 'Select Category'}
: $t('categories.select_category')}
</button>

{#if isOpen}
Expand All @@ -69,13 +62,13 @@
<div class="flex items-center gap-2">
<input
type="text"
placeholder="Category Name"
placeholder={$t('categories.category_name')}
class="input input-bordered w-full max-w-xs"
bind:value={new_category.display_name}
/>
<input
type="text"
placeholder="Icon"
placeholder={$t('categories.icon')}
class="input input-bordered w-full max-w-xs"
bind:value={new_category.icon}
/>
Expand All @@ -93,13 +86,6 @@
on:click={() => selectCategory(category)}
>
<span>{category.display_name} {category.icon} ({category.num_adventures})</span>
<!-- <button
type="button"
class="btn btn-xs btn-error"
on:click|stopPropagation={() => removeCategory(category.name)}
>
{$t('adventures.remove')}
</button> -->
</div>
{/each}
</div>
Expand Down
22 changes: 13 additions & 9 deletions frontend/src/lib/components/CategoryModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
let category_fetch = await fetch('/api/categories/categories');
categories = await category_fetch.json();
// remove the general category if it exists
categories = categories.filter((c) => c.name !== 'general');
// categories = categories.filter((c) => c.name !== 'general');
});
async function saveCategory() {
Expand Down Expand Up @@ -73,7 +73,7 @@
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div class="modal-box" role="dialog" on:keydown={handleKeydown} tabindex="0">
<h3 class="font-bold text-lg">Manage Categories</h3>
<h3 class="font-bold text-lg">{$t('categories.manage_categories')}</h3>

{#each categories as category}
<div class="flex justify-between items-center mt-2">
Expand All @@ -82,32 +82,36 @@
<button on:click={() => (category_to_edit = category)} class="btn btn-primary btn-sm"
>Edit</button
>
<button on:click={removeCategory(category)} class="btn btn-warning btn-sm">Remove</button>
{#if category.name != 'general'}
<button on:click={removeCategory(category)} class="btn btn-warning btn-sm"
>{$t('adventures.remove')}</button
>
{/if}
</div>
</div>
{/each}
{#if categories.length === 0}
<p>No categories found.</p>
<p>{$t('categories.no_categories_found')}</p>
{/if}

{#if category_to_edit}
<h2 class="text-center text-xl font-semibold mt-2 mb-2">Edit Category</h2>
<h2 class="text-center text-xl font-semibold mt-2 mb-2">{$t('categories.edit_category')}</h2>
<div class="flex flex-row space-x-2 form-control">
<input
type="text"
placeholder="Name"
placeholder={$t('adventures.name')}
bind:value={category_to_edit.display_name}
class="input input-bordered w-full max-w-xs"
/>

<input
type="text"
placeholder="Icon"
placeholder={$t('categories.icon')}
bind:value={category_to_edit.icon}
class="input input-bordered w-full max-w-xs"
/>
</div>
<button class="btn btn-primary" on:click={saveCategory}>Save</button>
<button class="btn btn-primary" on:click={saveCategory}>{$t('notes.save')}</button>
{/if}

<button class="btn btn-primary mt-4" on:click={close}>{$t('about.close')}</button>
Expand All @@ -127,7 +131,7 @@
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
></path>
</svg>
<span>The adventure cards will be updated once you refresh the page.</span>
<span>{$t('categories.update_after_refresh')}</span>
</div>
{/if}
</div>
Expand Down
70 changes: 27 additions & 43 deletions frontend/src/lib/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import PaletteOutline from '~icons/mdi/palette-outline';
import { page } from '$app/stores';
import { t, locale, locales } from 'svelte-i18n';
import { themes } from '$lib';
let query: string = '';
Expand Down Expand Up @@ -214,57 +215,40 @@
<button class="btn" on:click={() => (isAboutModalOpen = true)}>{$t('navbar.about')}</button>
<button
class="btn btn-sm mt-2"
on:click={() => (window.location.href = 'https://docs.adventurelog.app/')}
on:click={() => (window.location.href = 'https://adventurelog.app')}
>{$t('navbar.documentation')}</button
>
<button
class="btn btn-sm mt-2"
on:click={() => (window.location.href = 'https://discord.gg/wRbQ9Egr8C')}>Discord</button
>
<button
class="btn btn-sm mt-2"
on:click={() => (window.location.href = 'https://buymeacoffee.com/seanmorley15')}
>{$t('navbar.support')} 💖</button
>
<p class="font-bold m-4 text-lg text-center">{$t('navbar.language_selection')}</p>
<form method="POST" use:enhance>
<select
class="select select-bordered w-full max-w-xs bg-base-100 text-base-content"
on:change={submitLocaleChange}
bind:value={$locale}
>
{#each $locales as loc}
<option value={loc} class="text-base-content">{$t(`languages.${loc}`)}</option>
{/each}
</select>
<input type="hidden" name="locale" value={$locale} />
</form>
<p class="font-bold m-4 text-lg text-center">{$t('navbar.theme_selection')}</p>
<form method="POST" use:enhance={submitUpdateTheme}>
<li>
<button formaction="/?/setTheme&theme=light"
>{$t('navbar.themes.light')}<WeatherSunny class="w-6 h-6" />
</button>
</li>
<li>
<button formaction="/?/setTheme&theme=dark"
>{$t('navbar.themes.dark')}<WeatherNight class="w-6 h-6" /></button
>
</li>
<li>
<button formaction="/?/setTheme&theme=night"
>{$t('navbar.themes.night')}<WeatherNight class="w-6 h-6" /></button
>
</li>
<li>
<button formaction="/?/setTheme&theme=forest"
>{$t('navbar.themes.forest')}<Forest class="w-6 h-6" /></button
>
<button formaction="/?/setTheme&theme=aestheticLight"
>{$t('navbar.themes.aestetic-light')}<PaletteOutline class="w-6 h-6" /></button
>
<button formaction="/?/setTheme&theme=aestheticDark"
>{$t('navbar.themes.aestetic-dark')}<PaletteOutline class="w-6 h-6" /></button
>
<button formaction="/?/setTheme&theme=aqua"
>{$t('navbar.themes.aqua')}<Water class="w-6 h-6" /></button
>
</li>
<p class="font-bold m-4 text-lg text-center">{$t('navbar.language_selection')}</p>
<form method="POST" use:enhance>
<select
class="select select-bordered w-full max-w-xs bg-base-100 text-base-content"
on:change={submitLocaleChange}
bind:value={$locale}
>
{#each $locales as loc}
<option value={loc} class="text-base-content">{$t(`languages.${loc}`)}</option>
{/each}
</select>
<input type="hidden" name="locale" value={$locale} />
</form>
{#each themes as theme}
<li>
<button formaction="/?/setTheme&theme={theme.name}"
>{$t(`navbar.themes.${theme.name}`)}
</button>
</li>
{/each}
</form>
</ul>
</div>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,13 @@ export function findFirstValue(obj: any): any {
}
}
}

export let themes = [
{ name: 'light', label: 'Light' },
{ name: 'dark', label: 'Dark' },
{ name: 'night', label: 'Night' },
{ name: 'forest', label: 'Forest' },
{ name: 'aqua', label: 'Aqua' },
{ name: 'aestheticLight', label: 'Aesthetic Light' },
{ name: 'aestheticDark', label: 'Aesthetic Dark' }
];
21 changes: 16 additions & 5 deletions frontend/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@
"day": "Tag",
"add_a_tag": "Fügen Sie ein Tag hinzu",
"tags": "Schlagworte",
"set_to_pin": "Auf „Anpinnen“ setzen"
"set_to_pin": "Auf „Anpinnen“ setzen",
"category_fetch_error": "Fehler beim Abrufen der Kategorien"
},
"home": {
"desc_1": "Entdecken, planen und erkunden Sie mit Leichtigkeit",
Expand Down Expand Up @@ -219,19 +220,20 @@
"shared_with_me": "Mit mir geteilt",
"theme_selection": "Themenauswahl",
"themes": {
"aestetic-dark": "Ästhetisches Dunkel",
"aestetic-light": "Ästhetisches Licht",
"aqua": "Aqua",
"dark": "Dunkel",
"forest": "Wald",
"light": "Licht",
"night": "Nacht"
"night": "Nacht",
"aestheticDark": "Ästhetisches Dunkel",
"aestheticLight": "Ästhetisches Licht"
},
"users": "Benutzer",
"worldtravel": "Weltreisen",
"my_tags": "Meine Tags",
"tag": "Etikett",
"language_selection": "Sprache"
"language_selection": "Sprache",
"support": "Unterstützung"
},
"auth": {
"confirm_password": "Passwort bestätigen",
Expand Down Expand Up @@ -399,5 +401,14 @@
"user_stats": "Benutzerstatistiken",
"visited_countries": "Besuchte Länder",
"visited_regions": "Besuchte Regionen"
},
"categories": {
"category_name": "Kategoriename",
"edit_category": "Kategorie bearbeiten",
"icon": "Symbol",
"manage_categories": "Kategorien verwalten",
"no_categories_found": "Keine Kategorien gefunden.",
"select_category": "Kategorie auswählen",
"update_after_refresh": "Die Abenteuerkarten werden aktualisiert, sobald Sie die Seite aktualisieren."
}
}
14 changes: 12 additions & 2 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"documentation": "Documentation",
"discord": "Discord",
"language_selection": "Language",
"support": "Support",
"theme_selection": "Theme Selection",
"themes": {
"light": "Light",
"dark": "Dark",
"night": "Night",
"forest": "Forest",
"aestetic-dark": "Aestetic Dark",
"aestetic-light": "Aestetic Light",
"aestheticLight": "Aesthetic Light",
"aestheticDark": "Aesthetic Dark",
"aqua": "Aqua"
}
},
Expand Down Expand Up @@ -400,5 +401,14 @@
"user_stats": "User Stats",
"visited_countries": "Visited Countries",
"visited_regions": "Visited Regions"
},
"categories": {
"manage_categories": "Manage Categories",
"no_categories_found": "No categories found.",
"edit_category": "Edit Category",
"icon": "Icon",
"update_after_refresh": "The adventure cards will be updated once you refresh the page.",
"select_category": "Select Category",
"category_name": "Category Name"
}
}
21 changes: 16 additions & 5 deletions frontend/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
"dark": "Oscuro",
"night": "Noche",
"forest": "Bosque",
"aestetic-dark": "Estético Oscuro",
"aestetic-light": "Estético Claro",
"aqua": "Aqua"
"aqua": "Aqua",
"aestheticDark": "Estética Oscura",
"aestheticLight": "Luz estetica"
},
"my_tags": "Mis etiquetas",
"tag": "Etiqueta",
"language_selection": "Idioma"
"language_selection": "Idioma",
"support": "Apoyo"
},
"about": {
"about": "Acerca de",
Expand Down Expand Up @@ -231,7 +232,8 @@
"day": "Día",
"add_a_tag": "Agregar una etiqueta",
"tags": "Etiquetas",
"set_to_pin": "Establecer en Fijar"
"set_to_pin": "Establecer en Fijar",
"category_fetch_error": "Error al buscar categorías"
},
"worldtravel": {
"all": "Todo",
Expand Down Expand Up @@ -399,5 +401,14 @@
"user_stats": "Estadísticas de usuario",
"visited_countries": "Países visitados",
"visited_regions": "Regiones visitadas"
},
"categories": {
"category_name": "Nombre de categoría",
"edit_category": "Editar categoría",
"icon": "Icono",
"manage_categories": "Administrar categorías",
"no_categories_found": "No se encontraron categorías.",
"select_category": "Seleccionar categoría",
"update_after_refresh": "Las tarjetas de aventuras se actualizarán una vez que actualices la página."
}
}
Loading

0 comments on commit adf45ff

Please sign in to comment.