1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 21:09:37 +02:00

Convert indentation to tabs, as my vscode did not want to cooperate

This commit is contained in:
Thies 2025-01-30 13:02:49 +01:00
parent 94fca45af0
commit cc6a98d23b
No known key found for this signature in database
4 changed files with 81 additions and 80 deletions

View file

@ -1257,7 +1257,7 @@ it would also work to just use on:click on the MapLibre component itself. -->
{#if immichIntegration} {#if immichIntegration}
<ImmichSelect <ImmichSelect
adventure={adventure} adventure={adventure}
on:fetchImage={(e) => { on:fetchImage={(e) => {
url = e.detail; url = e.detail;
fetchImage(); fetchImage();

View file

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { createEventDispatcher, onMount } from 'svelte'; import { createEventDispatcher, onMount } from 'svelte';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
import ImmichLogo from '$lib/assets/immich.svg'; import ImmichLogo from '$lib/assets/immich.svg';
import type { Adventure, ImmichAlbum } from '$lib/types'; import type { Adventure, ImmichAlbum } from '$lib/types';
import { debounce } from '$lib'; import { debounce } from '$lib';
@ -10,67 +10,68 @@
let searchCategory: 'search' | 'date' | 'album' = 'date'; let searchCategory: 'search' | 'date' | 'album' = 'date';
let immichError: string = ''; let immichError: string = '';
let immichNextURL: string = ''; let immichNextURL: string = '';
let loading = false; let loading = false;
export let adventure: Adventure | null = null; export let adventure: Adventure | null = null;
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
let albums: ImmichAlbum[] = []; let albums: ImmichAlbum[] = [];
let currentAlbum: string = ''; let currentAlbum: string = '';
let selectedDate: string = (adventure as Adventure | null)?.visits.map(v => new Date(v.end_date || v.start_date)).sort((a,b) => +b - +a)[0]?.toISOString().split('T')[0] || ''; let selectedDate: string = (adventure as Adventure | null)?.visits.map(v => new Date(v.end_date || v.start_date)).sort((a,b) => +b - +a)[0]?.toISOString()?.split('T')[0] || '';
if (!selectedDate) { if (!selectedDate) {
selectedDate = new Date().toISOString().split('T')[0]; selectedDate = new Date().toISOString().split('T')[0];
} }
$: { $: {
if (currentAlbum) { if (currentAlbum) {
immichImages = []; immichImages = [];
fetchAlbumAssets(currentAlbum); fetchAlbumAssets(currentAlbum);
} else if (searchCategory === 'date' && selectedDate) { } else if (searchCategory === 'date' && selectedDate) {
searchImmich(); searchImmich();
} }
} }
async function loadMoreImmich() { async function loadMoreImmich() {
// The next URL returned by our API is a absolute url to API, but we need to use the relative path, to use the frontend api proxy. // The next URL returned by our API is a absolute url to API, but we need to use the relative path, to use the frontend api proxy.
const url = new URL(immichNextURL); const url = new URL(immichNextURL);
immichNextURL = url.pathname + url.search; immichNextURL = url.pathname + url.search;
return fetchAssets(immichNextURL, true); return fetchAssets(immichNextURL, true);
} }
async function fetchAssets(url: string, usingNext = false) { async function fetchAssets(url: string, usingNext = false) {
loading = true; loading = true;
try { try {
let res = await fetch(url); let res = await fetch(url);
immichError = ''; immichError = '';
if (!res.ok) { if (!res.ok) {
let data = await res.json(); let data = await res.json();
let errorMessage = data.message; let errorMessage = data.message;
console.error('Error in handling fetchAsstes', errorMessage); console.error('Error in handling fetchAsstes', errorMessage);
immichError = $t(data.code); immichError = $t(data.code);
} else { } else {
let data = await res.json(); let data = await res.json();
if (data.results && data.results.length > 0) { if (data.results && data.results.length > 0) {
if (usingNext) { if (usingNext) {
immichImages = [...immichImages, ...data.results]; immichImages = [...immichImages, ...data.results];
} else { } else {
immichImages = data.results; immichImages = data.results;
} }
} else { } else {
immichError = $t('immich.no_items_found'); immichError = $t('immich.no_items_found');
} }
immichNextURL = data.next || ''; immichNextURL = data.next || '';
} }
} finally { } finally {
loading = false; loading = false;
} }
} }
async function fetchAlbumAssets(album_id: string,) { async function fetchAlbumAssets(album_id: string,) {
return fetchAssets(`/api/integrations/immich/albums/${album_id}`); return fetchAssets(`/api/integrations/immich/albums/${album_id}`);
} }
onMount(async () => { onMount(async () => {
@ -82,22 +83,22 @@
}); });
function buildQueryParams() { function buildQueryParams() {
let params = new URLSearchParams(); let params = new URLSearchParams();
if (immichSearchValue && searchCategory === 'search') { if (immichSearchValue && searchCategory === 'search') {
params.append('query', immichSearchValue); params.append('query', immichSearchValue);
} else if (selectedDate && searchCategory === 'date') { } else if (selectedDate && searchCategory === 'date') {
params.append('date', selectedDate); params.append('date', selectedDate);
} }
return params.toString(); return params.toString();
} }
const searchImmich = debounce(() => { const searchImmich = debounce(() => {
_searchImmich(); _searchImmich();
}, 500); // Debounce the search function to avoid multiple requests on every key press }, 500); // Debounce the search function to avoid multiple requests on every key press
async function _searchImmich() { async function _searchImmich() {
return fetchAssets(`/api/integrations/immich/search/?${buildQueryParams()}`); return fetchAssets(`/api/integrations/immich/search/?${buildQueryParams()}`);
} }
</script> </script>
@ -117,7 +118,7 @@
value="search" value="search"
aria-label="Search" aria-label="Search"
/> />
<input <input
type="radio" type="radio"
class="join-item btn" class="join-item btn"
bind:group={searchCategory} bind:group={searchCategory}
@ -143,12 +144,12 @@
/> />
<button type="submit" class="btn btn-neutral mt-2">Search</button> <button type="submit" class="btn btn-neutral mt-2">Search</button>
</form> </form>
{:else if searchCategory === 'date'} {:else if searchCategory === 'date'}
<input <input
type="date" type="date"
bind:value={selectedDate} bind:value={selectedDate}
class="input input-bordered w-full max-w-xs mt-2" class="input input-bordered w-full max-w-xs mt-2"
/> />
{:else if searchCategory === 'album'} {:else if searchCategory === 'album'}
<select class="select select-bordered w-full max-w-xs mt-2" bind:value={currentAlbum}> <select class="select select-bordered w-full max-w-xs mt-2" bind:value={currentAlbum}>
<option value="" disabled selected>Select an Album</option> <option value="" disabled selected>Select an Album</option>
@ -162,11 +163,11 @@
<p class="text-red-500">{immichError}</p> <p class="text-red-500">{immichError}</p>
<div class="flex flex-wrap gap-4 mr-4 mt-2"> <div class="flex flex-wrap gap-4 mr-4 mt-2">
{#if loading} {#if loading}
<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-[100] w-24 h-24"> <div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-[100] w-24 h-24">
<span class="loading loading-spinner w-24 h-24"></span> <span class="loading loading-spinner w-24 h-24"></span>
</div> </div>
{/if} {/if}
{#each immichImages as image} {#each immichImages as image}
<div class="flex flex-col items-center gap-2" class:blur-sm={loading}> <div class="flex flex-col items-center gap-2" class:blur-sm={loading}>
@ -176,9 +177,9 @@
alt="Image from Immich" alt="Image from Immich"
class="h-24 w-24 object-cover rounded-md" class="h-24 w-24 object-cover rounded-md"
/> />
<h4> <h4>
{image.fileCreatedAt?.split('T')[0] || "Unknown"} {image.fileCreatedAt?.split('T')[0] || "Unknown"}
</h4> </h4>
<button <button
type="button" type="button"
class="btn btn-sm btn-primary" class="btn btn-sm btn-primary"

View file

@ -17,10 +17,10 @@
// Event listener for focusing input // Event listener for focusing input
function handleKeydown(event: KeyboardEvent) { function handleKeydown(event: KeyboardEvent) {
// Ignore any keypresses in an input/textarea field, so we don't interfere with typing. // Ignore any keypresses in an input/textarea field, so we don't interfere with typing.
if (event.key === '/' && !["INPUT", "TEXTAREA"].includes((event.target as HTMLElement)?.tagName)) { if (event.key === '/' && !["INPUT", "TEXTAREA"].includes((event.target as HTMLElement)?.tagName)) {
event.preventDefault(); // Prevent browser's search shortcut event.preventDefault(); // Prevent browser's search shortcut
if (inputElement) { if (inputElement) {
inputElement.focus(); inputElement.focus();
} }
} }
@ -223,7 +223,7 @@
bind:value={query} bind:value={query}
class="grow" class="grow"
placeholder={$t('navbar.search')} placeholder={$t('navbar.search')}
bind:this={inputElement} bind:this={inputElement}
/><kbd class="kbd">/</kbd> /><kbd class="kbd">/</kbd>
</label> </label>
<button on:click={searchGo} type="submit" class="btn btn-neutral" <button on:click={searchGo} type="submit" class="btn btn-neutral"

View file

@ -466,11 +466,11 @@ export function osmTagToEmoji(tag: string) {
} }
export function debounce(func: Function, timeout: number) { export function debounce(func: Function, timeout: number) {
let timer: number | NodeJS.Timeout; let timer: number | NodeJS.Timeout;
return (...args: any) => { return (...args: any) => {
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(() => { timer = setTimeout(() => {
func(...args); func(...args);
}, timeout); }, timeout);
}; };
} }