2022-05-21 02:23:55 -05:00
|
|
|
<script context="module" lang="ts">
|
2022-05-21 23:28:02 -05:00
|
|
|
export const prerender = false;
|
|
|
|
|
2022-05-21 02:23:55 -05:00
|
|
|
import type { Load } from '@sveltejs/kit';
|
2022-05-27 14:02:06 -05:00
|
|
|
import { getAssetsInfo } from '$lib/stores/assets';
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2022-05-27 14:02:06 -05:00
|
|
|
export const load: Load = async ({ session }) => {
|
2022-05-21 02:23:55 -05:00
|
|
|
if (!session.user) {
|
|
|
|
return {
|
|
|
|
status: 302,
|
|
|
|
redirect: '/auth/login',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-10 21:41:45 -05:00
|
|
|
await getAssetsInfo(session.user.accessToken);
|
|
|
|
|
2022-05-21 02:23:55 -05:00
|
|
|
return {
|
|
|
|
status: 200,
|
|
|
|
props: {
|
|
|
|
user: session.user,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import type { ImmichUser } from '$lib/models/immich-user';
|
|
|
|
|
2022-07-08 21:26:50 -05:00
|
|
|
import NavigationBar from '$lib/components/shared/navigation-bar.svelte';
|
2022-05-21 02:23:55 -05:00
|
|
|
import SideBarButton from '$lib/components/shared/side-bar-button.svelte';
|
2022-05-27 14:02:06 -05:00
|
|
|
import CheckCircle from 'svelte-material-icons/CheckCircle.svelte';
|
2022-06-03 11:04:30 -05:00
|
|
|
|
2022-05-21 02:23:55 -05:00
|
|
|
import ImageOutline from 'svelte-material-icons/ImageOutline.svelte';
|
|
|
|
import { AppSideBarSelection } from '$lib/models/admin-sidebar-selection';
|
2022-07-10 21:41:45 -05:00
|
|
|
import { onMount } from 'svelte';
|
2022-06-03 11:04:30 -05:00
|
|
|
import { fly } from 'svelte/transition';
|
2022-05-21 16:50:56 -05:00
|
|
|
import { session } from '$app/stores';
|
2022-05-27 14:02:06 -05:00
|
|
|
import { assetsGroupByDate, flattenAssetGroupByDate } from '$lib/stores/assets';
|
2022-07-08 21:26:50 -05:00
|
|
|
import ImmichThumbnail from '$lib/components/asset-viewer/immich-thumbnail.svelte';
|
2022-05-21 16:50:56 -05:00
|
|
|
import moment from 'moment';
|
2022-07-08 21:26:50 -05:00
|
|
|
import AssetViewer from '$lib/components/asset-viewer/asset-viewer.svelte';
|
|
|
|
import StatusBox from '$lib/components/shared/status-box.svelte';
|
|
|
|
import { fileUploader } from '$lib/utils/file-uploader';
|
2022-07-10 21:41:45 -05:00
|
|
|
import { AssetResponseDto } from '@api';
|
2022-05-21 02:23:55 -05:00
|
|
|
|
|
|
|
export let user: ImmichUser;
|
2022-07-08 21:26:50 -05:00
|
|
|
|
2022-05-21 02:23:55 -05:00
|
|
|
let selectedAction: AppSideBarSelection;
|
2022-05-21 16:50:56 -05:00
|
|
|
|
2022-05-27 14:02:06 -05:00
|
|
|
let selectedGroupThumbnail: number | null;
|
|
|
|
let isMouseOverGroup: boolean;
|
|
|
|
$: if (isMouseOverGroup == false) {
|
|
|
|
selectedGroupThumbnail = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let isShowAsset = false;
|
|
|
|
let currentViewAssetIndex = 0;
|
2022-07-10 21:41:45 -05:00
|
|
|
let currentSelectedAsset: AssetResponseDto;
|
2022-05-21 02:23:55 -05:00
|
|
|
|
|
|
|
const onButtonClicked = (buttonType: CustomEvent) => {
|
|
|
|
selectedAction = buttonType.detail['actionType'] as AppSideBarSelection;
|
|
|
|
};
|
|
|
|
|
2022-05-21 16:50:56 -05:00
|
|
|
onMount(async () => {
|
2022-05-21 02:23:55 -05:00
|
|
|
selectedAction = AppSideBarSelection.PHOTOS;
|
2022-07-01 12:00:12 -05:00
|
|
|
});
|
|
|
|
|
2022-05-27 14:02:06 -05:00
|
|
|
const thumbnailMouseEventHandler = (event: CustomEvent) => {
|
|
|
|
const { selectedGroupIndex }: { selectedGroupIndex: number } = event.detail;
|
|
|
|
|
|
|
|
selectedGroupThumbnail = selectedGroupIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
const viewAssetHandler = (event: CustomEvent) => {
|
|
|
|
const { assetId, deviceId }: { assetId: string; deviceId: string } = event.detail;
|
|
|
|
|
|
|
|
currentViewAssetIndex = $flattenAssetGroupByDate.findIndex((a) => a.id == assetId);
|
|
|
|
currentSelectedAsset = $flattenAssetGroupByDate[currentViewAssetIndex];
|
|
|
|
isShowAsset = true;
|
2022-06-19 08:16:35 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const uploadClickedHandler = async () => {
|
|
|
|
if ($session.user) {
|
|
|
|
try {
|
|
|
|
let fileSelector = document.createElement('input');
|
|
|
|
|
|
|
|
fileSelector.type = 'file';
|
|
|
|
fileSelector.multiple = true;
|
|
|
|
fileSelector.accept = 'image/*,video/*,.heic,.heif';
|
|
|
|
|
|
|
|
fileSelector.onchange = async (e: any) => {
|
|
|
|
const files = Array.from<File>(e.target.files);
|
|
|
|
|
|
|
|
const acceptedFile = files.filter(
|
|
|
|
(e) => e.type.split('/')[0] === 'video' || e.type.split('/')[0] === 'image',
|
|
|
|
);
|
|
|
|
|
|
|
|
for (const asset of acceptedFile) {
|
|
|
|
await fileUploader(asset, $session.user!.accessToken);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fileSelector.click();
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Error seelcting file', e);
|
|
|
|
}
|
|
|
|
}
|
2022-05-27 14:02:06 -05:00
|
|
|
};
|
2022-05-21 02:23:55 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<svelte:head>
|
|
|
|
<title>Immich - Photos</title>
|
|
|
|
</svelte:head>
|
|
|
|
|
|
|
|
<section>
|
2022-06-19 08:16:35 -05:00
|
|
|
<NavigationBar {user} on:uploadClicked={uploadClickedHandler} />
|
2022-05-21 02:23:55 -05:00
|
|
|
</section>
|
|
|
|
|
2022-06-19 08:16:35 -05:00
|
|
|
<section class="grid grid-cols-[250px_auto] relative pt-[72px] h-screen bg-immich-bg">
|
2022-05-27 14:02:06 -05:00
|
|
|
<!-- Sidebar -->
|
2022-06-06 03:12:12 +01:00
|
|
|
<section id="sidebar" class="flex flex-col gap-4 pt-8 pr-6">
|
2022-05-21 02:23:55 -05:00
|
|
|
<SideBarButton
|
|
|
|
title="Photos"
|
|
|
|
logo={ImageOutline}
|
|
|
|
actionType={AppSideBarSelection.PHOTOS}
|
|
|
|
isSelected={selectedAction === AppSideBarSelection.PHOTOS}
|
|
|
|
on:selected={onButtonClicked}
|
|
|
|
/>
|
2022-06-05 05:15:39 -05:00
|
|
|
|
|
|
|
<!-- Status Box -->
|
|
|
|
|
2022-06-06 03:12:12 +01:00
|
|
|
<div class="mb-6 mt-auto">
|
2022-06-05 05:15:39 -05:00
|
|
|
<StatusBox />
|
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
</section>
|
|
|
|
|
2022-05-27 14:02:06 -05:00
|
|
|
<!-- Main Section -->
|
2022-05-21 02:23:55 -05:00
|
|
|
<section class="overflow-y-auto relative">
|
2022-06-19 08:16:35 -05:00
|
|
|
<section id="assets-content" class="relative pt-8 pl-4 mb-12 bg-immich-bg">
|
2022-05-27 14:02:06 -05:00
|
|
|
<section id="image-grid" class="flex flex-wrap gap-14">
|
|
|
|
{#each $assetsGroupByDate as assetsInDateGroup, groupIndex}
|
|
|
|
<!-- Asset Group By Date -->
|
|
|
|
<div
|
|
|
|
class="flex flex-col"
|
|
|
|
on:mouseenter={() => (isMouseOverGroup = true)}
|
|
|
|
on:mouseleave={() => (isMouseOverGroup = false)}
|
|
|
|
>
|
|
|
|
<!-- Date group title -->
|
2022-06-19 08:16:35 -05:00
|
|
|
<p class="font-medium text-sm text-immich-fg mb-2 flex place-items-center h-6">
|
2022-05-27 14:02:06 -05:00
|
|
|
{#if selectedGroupThumbnail === groupIndex && isMouseOverGroup}
|
|
|
|
<div
|
|
|
|
in:fly={{ x: -24, duration: 200, opacity: 0.5 }}
|
|
|
|
out:fly={{ x: -24, duration: 200 }}
|
|
|
|
class="inline-block px-2 hover:cursor-pointer"
|
|
|
|
>
|
|
|
|
<CheckCircle size="24" color="#757575" />
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
2022-05-21 16:50:56 -05:00
|
|
|
{moment(assetsInDateGroup[0].createdAt).format('ddd, MMM DD YYYY')}
|
|
|
|
</p>
|
2022-05-27 14:02:06 -05:00
|
|
|
|
|
|
|
<!-- Image grid -->
|
2022-06-19 08:16:35 -05:00
|
|
|
<div class="flex flex-wrap gap-[2px]">
|
2022-05-21 16:50:56 -05:00
|
|
|
{#each assetsInDateGroup as asset}
|
2022-05-27 14:02:06 -05:00
|
|
|
<ImmichThumbnail
|
|
|
|
{asset}
|
|
|
|
on:mouseEvent={thumbnailMouseEventHandler}
|
|
|
|
on:viewAsset={viewAssetHandler}
|
|
|
|
{groupIndex}
|
|
|
|
/>
|
2022-05-21 16:50:56 -05:00
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</section>
|
2022-05-21 02:23:55 -05:00
|
|
|
</section>
|
|
|
|
</section>
|
|
|
|
</section>
|
2022-05-27 14:02:06 -05:00
|
|
|
|
|
|
|
<!-- Overlay Asset Viewer -->
|
|
|
|
{#if isShowAsset}
|
2022-06-03 11:04:30 -05:00
|
|
|
<AssetViewer
|
|
|
|
selectedAsset={currentSelectedAsset}
|
|
|
|
selectedIndex={currentViewAssetIndex}
|
|
|
|
on:close={() => (isShowAsset = false)}
|
|
|
|
/>
|
2022-05-27 14:02:06 -05:00
|
|
|
{/if}
|