Skip to content

Commit

Permalink
minor refactoring (#2689)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Nov 15, 2024
1 parent 0f32f23 commit 14514f4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions resources/js/components/gallery/thumbs/AlbumThumbImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function onImageLoad() {
function load(thumb: App.Http.Resources.Models.ThumbResource | undefined | null, isPasswordProtected: boolean) {
if (isNotEmpty(thumb?.placeholder)) {
placeholderSrc.value = thumb?.placeholder as string;
placeholderSrc.value = thumb.placeholder;
}
if (thumb?.thumb === "uploads/thumb/") {
src.value = getPlaceholderIcon();
Expand All @@ -64,9 +64,9 @@ function load(thumb: App.Http.Resources.Models.ThumbResource | undefined | null,
src.value = getNoImageIcon();
}
} else {
src.value = isNotEmpty(thumb?.thumb) ? (thumb?.thumb as string) : isPasswordProtected ? getPaswwordIcon() : getNoImageIcon();
src.value = isNotEmpty(thumb?.thumb) ? thumb.thumb : isPasswordProtected ? getPaswwordIcon() : getNoImageIcon();
}
srcSet.value = isNotEmpty(thumb?.thumb2x) ? (thumb?.thumb2x as string) : "";
srcSet.value = isNotEmpty(thumb?.thumb2x) ? thumb.thumb2x : "";
}
load(props.thumb, props.isPasswordProtected);
Expand Down
4 changes: 0 additions & 4 deletions resources/js/composables/photo/basePhoto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import Constants from "@/services/constants";
import { computed, Ref, ref } from "vue";

export function usePhotoBaseFunction(photoId: Ref<string>) {
const photo = ref(undefined) as Ref<App.Http.Resources.Models.PhotoResource | undefined>;
const album = ref(null) as Ref<App.Http.Resources.Models.AbstractAlbumResource | null>;
const photos = ref([]) as Ref<App.Http.Resources.Models.PhotoResource[]>;

const placeholder = Constants.BASE_URL + "/img/placeholder.png";

function hasPrevious(): boolean {
return photo.value?.previous_photo_id !== null;
}
Expand Down Expand Up @@ -96,7 +93,6 @@ export function usePhotoBaseFunction(photoId: Ref<string>) {
photo,
album,
photos,
placeholder,
previousStyle,
nextStyle,
srcSetMedium,
Expand Down
2 changes: 1 addition & 1 deletion resources/js/utils/Helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Constants from "@/services/constants";

export function useImageHelpers() {
function isNotEmpty(link: string | null | undefined): boolean {
function isNotEmpty(link: string | null | undefined): link is string {
return link !== "" && link !== null && link !== undefined;
}

Expand Down
6 changes: 4 additions & 2 deletions resources/js/views/gallery-panels/Photo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
id="image"
alt="placeholder"
class="absolute m-auto w-auto h-auto animate-zoomIn bg-contain bg-center bg-no-repeat"
:src="placeholder"
:src="getPlaceholderIcon()"
/>
<!-- This is a normal image: medium or original -->
<img
Expand Down Expand Up @@ -165,6 +165,7 @@ import { useSlideshowFunction } from "@/composables/photo/slideshow";
import { useToast } from "primevue/usetoast";
import type { UseSwipeDirection } from "@vueuse/core";
import { useSwipe } from "@vueuse/core";
import { useImageHelpers } from "@/utils/Helpers";
const swipe = ref<HTMLElement | null>(null);
Expand All @@ -183,8 +184,9 @@ const { is_upload_visible } = storeToRefs(lycheeStore);
const { isDeleteVisible, toggleDelete, isMoveVisible, toggleMove } = useGalleryModals(is_upload_visible);
const photoId = ref(props.photoid);
const { photo, album, photos, placeholder, previousStyle, nextStyle, srcSetMedium, style, imageViewMode, refresh, hasPrevious, hasNext } =
const { photo, album, photos, previousStyle, nextStyle, srcSetMedium, style, imageViewMode, refresh, hasPrevious, hasNext } =
usePhotoBaseFunction(photoId);
const { getPlaceholderIcon } = useImageHelpers();
const { is_full_screen, is_edit_open, are_details_open, is_slideshow_active, slideshow_timeout } = storeToRefs(lycheeStore);
Expand Down

0 comments on commit 14514f4

Please sign in to comment.