80 lines
2.1 KiB
JavaScript
80 lines
2.1 KiB
JavaScript
import {defineStore} from "pinia";
|
|
import {ADJUST_PHOTO, CHANGE_PHOTO_ORIENTATION, DELETE_PHOTO, EDIT_PHOTO, UPLOAD_PHOTO} from "src/graphql/mutations/photo";
|
|
import {PHOTO_DETAIL} from "src/graphql/queries/photo";
|
|
import {ref} from "vue";
|
|
import {mutate, query} from "stores/helpers";
|
|
|
|
export const usePhotosStore = defineStore('Photos', () => {
|
|
const photo = ref(null);
|
|
const isMutationRunning = ref(false);
|
|
const isQueryRunning = ref(false);
|
|
|
|
const fetchDetail = (id) => query({
|
|
isQueryRunning,
|
|
query: PHOTO_DETAIL,
|
|
variables: {id}
|
|
}).then(item => photo.value = item);
|
|
|
|
const upload = (flightId, input) => {
|
|
if (!flightId) {
|
|
console.error("No flightId specified for photo upload! Aborting");
|
|
return;
|
|
}
|
|
|
|
input.flightId = flightId;
|
|
|
|
if (!input.name) {
|
|
input.name = "";
|
|
}
|
|
|
|
if (!input.description) {
|
|
input.description = "";
|
|
}
|
|
|
|
// TODO: ^^ patri tohle do storu?
|
|
|
|
return mutate({
|
|
isMutationRunning,
|
|
mutation: UPLOAD_PHOTO,
|
|
variables: {input}
|
|
})
|
|
};
|
|
|
|
const update = (id, input) => mutate({
|
|
isMutationRunning,
|
|
mutation: EDIT_PHOTO,
|
|
variables: {id, input}
|
|
}).then(item => {
|
|
photo.value = item;
|
|
return item;
|
|
})
|
|
|
|
const changeOrientation = (id, direction) => mutate({
|
|
isMutationRunning,
|
|
mutation: CHANGE_PHOTO_ORIENTATION,
|
|
variables: {id, direction}
|
|
}).then(item => {
|
|
photo.value = item;
|
|
return item;
|
|
});
|
|
|
|
const adjust = (id, adjustment) => mutate({
|
|
isMutationRunning,
|
|
mutation: ADJUST_PHOTO,
|
|
variables: {id, adjustment}
|
|
}).then(item => {
|
|
photo.value = item;
|
|
return item;
|
|
});
|
|
|
|
const destroy = (id) => mutate({
|
|
isMutationRunning,
|
|
mutation: DELETE_PHOTO,
|
|
variables: {id}
|
|
});
|
|
|
|
return {
|
|
photo, isMutationRunning, isQueryRunning, fetchDetail, upload, update, changeOrientation, adjust, destroy
|
|
}
|
|
});
|