forked from immich-app/immich
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): unlink live photos (immich-app#12574)
feat(web): unlink live photo
- Loading branch information
Showing
15 changed files
with
148 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 43 additions & 12 deletions
55
web/src/lib/components/photos-page/actions/link-live-photo-action.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,75 @@ | ||
<script lang="ts"> | ||
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte'; | ||
import type { OnLink } from '$lib/utils/actions'; | ||
import { AssetTypeEnum, updateAsset } from '@immich/sdk'; | ||
import { mdiMotionPlayOutline, mdiTimerSand } from '@mdi/js'; | ||
import type { OnLink, OnUnlink } from '$lib/utils/actions'; | ||
import { handleError } from '$lib/utils/handle-error'; | ||
import { AssetTypeEnum, getAssetInfo, updateAsset } from '@immich/sdk'; | ||
import { mdiLinkOff, mdiMotionPlayOutline, mdiTimerSand } from '@mdi/js'; | ||
import { t } from 'svelte-i18n'; | ||
import MenuOption from '../../shared-components/context-menu/menu-option.svelte'; | ||
import { getAssetControlContext } from '../asset-select-control-bar.svelte'; | ||
export let onLink: OnLink; | ||
export let onUnlink: OnUnlink; | ||
export let menuItem = false; | ||
export let unlink = false; | ||
let loading = false; | ||
const text = $t('link_motion_video'); | ||
const icon = mdiMotionPlayOutline; | ||
$: text = unlink ? $t('unlink_motion_video') : $t('link_motion_video'); | ||
$: icon = unlink ? mdiLinkOff : mdiMotionPlayOutline; | ||
const { clearSelect, getOwnedAssets } = getAssetControlContext(); | ||
const onClick = () => (unlink ? handleUnlink() : handleLink()); | ||
const handleLink = async () => { | ||
let [still, motion] = [...getOwnedAssets()]; | ||
if (still.type === AssetTypeEnum.Video) { | ||
[still, motion] = [motion, still]; | ||
} | ||
loading = true; | ||
const response = await updateAsset({ id: still.id, updateAssetDto: { livePhotoVideoId: motion.id } }); | ||
onLink(response); | ||
clearSelect(); | ||
loading = false; | ||
try { | ||
loading = true; | ||
const stillResponse = await updateAsset({ id: still.id, updateAssetDto: { livePhotoVideoId: motion.id } }); | ||
onLink({ still: stillResponse, motion }); | ||
clearSelect(); | ||
} catch (error) { | ||
handleError(error, $t('errors.unable_to_link_motion_video')); | ||
} finally { | ||
loading = false; | ||
} | ||
}; | ||
const handleUnlink = async () => { | ||
const [still] = [...getOwnedAssets()]; | ||
const motionId = still?.livePhotoVideoId; | ||
if (!motionId) { | ||
return; | ||
} | ||
try { | ||
loading = true; | ||
const stillResponse = await updateAsset({ id: still.id, updateAssetDto: { livePhotoVideoId: null } }); | ||
const motionResponse = await getAssetInfo({ id: motionId }); | ||
onUnlink({ still: stillResponse, motion: motionResponse }); | ||
clearSelect(); | ||
} catch (error) { | ||
handleError(error, $t('errors.unable_to_unlink_motion_video')); | ||
} finally { | ||
loading = false; | ||
} | ||
}; | ||
</script> | ||
|
||
{#if menuItem} | ||
<MenuOption {text} {icon} onClick={handleLink} /> | ||
<MenuOption {text} {icon} {onClick} /> | ||
{/if} | ||
|
||
{#if !menuItem} | ||
{#if loading} | ||
<CircleIconButton title={$t('loading')} icon={mdiTimerSand} /> | ||
{:else} | ||
<CircleIconButton title={text} {icon} on:click={handleLink} /> | ||
<CircleIconButton title={text} {icon} on:click={onClick} /> | ||
{/if} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters