-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
basePhoto.ts
106 lines (91 loc) · 2.92 KB
/
basePhoto.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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;
}
function hasNext(): boolean {
return photo.value?.next_photo_id !== null;
}
const previousStyle = computed(() => {
if (!hasPrevious()) {
return "";
}
const previousId = photo.value?.previous_photo_id;
const previousPhoto = photos.value.find((p) => p.id === previousId);
if (previousPhoto === undefined) {
return "";
}
return "background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url('" + previousPhoto.size_variants.thumb?.url + "')";
});
const nextStyle = computed(() => {
if (!hasNext()) {
return "";
}
const nextId = photo.value?.next_photo_id;
const nextPhoto = photos.value.find((p) => p.id === nextId);
if (nextPhoto === undefined) {
return "";
}
return "background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url('" + nextPhoto.size_variants.thumb?.url + "')";
});
const srcSetMedium = computed(() => {
const medium = photo.value?.size_variants.medium ?? null;
const medium2x = photo.value?.size_variants.medium2x ?? null;
if (medium === null || medium2x === null) {
return "";
}
return `${medium.url} ${medium.width}w, ${medium2x.url} ${medium2x.width}w`;
});
const style = computed(() => {
if (!photo.value?.precomputed.is_livephoto) {
return "background-image: url(" + photo.value?.size_variants.small?.url + ")";
}
if (photo.value?.size_variants.medium !== null) {
return "width: " + photo.value?.size_variants.medium.width + "px; height: " + photo.value?.size_variants.medium.height + "px";
}
if (photo.value?.size_variants.original === null) {
return "";
}
return "width: " + photo.value?.size_variants.original.width + "px; height: " + photo.value?.size_variants.original.height + "px";
});
const imageViewMode = computed(() => {
if (photo.value?.precomputed.is_video) {
return 0;
}
if (photo.value?.precomputed.is_raw) {
return 1;
}
if (!photo.value?.precomputed.is_livephoto) {
if (photo.value?.size_variants.medium !== null) {
return 2;
}
return 3;
}
if (photo.value?.size_variants.medium !== null) {
return 4;
}
return 5;
});
function refresh(): void {
photo.value = photos.value.find((p: App.Http.Resources.Models.PhotoResource) => p.id === photoId.value);
}
return {
photo,
album,
photos,
placeholder,
previousStyle,
nextStyle,
srcSetMedium,
style,
imageViewMode,
refresh,
hasPrevious,
hasNext,
};
}