diff --git a/web/frontend/src/TagManagement.svelte b/web/frontend/src/TagManagement.svelte
index 296f748..6ab4752 100644
--- a/web/frontend/src/TagManagement.svelte
+++ b/web/frontend/src/TagManagement.svelte
@@ -15,33 +15,36 @@
let pendingChange = false
let isOpen = false
+ const client = getContextClient();
+
const createTagMutation = ({ type, name }) => {
- result = mutationStore({
- client: getContextClient(),
- query: gql`mutation($type: String!, $name: String!) {
- createTag(type: $type, name: $name) { id, type, name }
- }`,
- variables: { type, name}
- })
+ return mutationStore({
+ client: client,
+ query: gql`mutation($type: String!, $name: String!) {
+ createTag(type: $type, name: $name) { id, type, name }
+ }`,
+ variables: { type, name}
+ })
}
const addTagsToJobMutation = ({ job, tagIds }) => {
- result = mutationStore({
- client: getContextClient(),
- query: gql`mutation($job: ID!, $tagIds: [ID!]!) {
- addTagsToJob(job: $job, tagIds: $tagIds) { id, type, name }
- }`,
- variables: {job, tagIds}
- })
+ return mutationStore({
+ client: client,
+ query: gql`mutation($job: ID!, $tagIds: [ID!]!) {
+ addTagsToJob(job: $job, tagIds: $tagIds) { id, type, name }
+ }`,
+ variables: {job, tagIds}
+ })
}
const removeTagsFromJobMutation = ({ job, tagIds }) => {
- result = mutationStore({
- client: getContextClient(),
- query: gql`mutation($job: ID!, $tagIds: [ID!]!) {
- removeTagsFromJob(job: $job, tagIds: $tagIds) { id, type, name }
- }`
- })
+ return mutationStore({
+ client: client,
+ query: gql`mutation($job: ID!, $tagIds: [ID!]!) {
+ removeTagsFromJob(job: $job, tagIds: $tagIds) { id, type, name }
+ }`,
+ variables: {job, tagIds}
+ })
}
let allTagsFiltered // $initialized is in there because when it becomes true, allTags is initailzed.
@@ -66,43 +69,47 @@
function createTag(type, name) {
pendingChange = true
- return createTagMutation({ type: type, name: name })
- .then(res => {
- if (res.error)
- throw res.error
-
+ createTagMutation({ type: type, name: name })
+ .subscribe(res => {
+ if (res.fetching === false && !res.error) {
pendingChange = false
allTags = [...allTags, res.data.createTag]
newTagType = ''
newTagName = ''
- return res.data.createTag
- }, err => console.error(err))
+ addTagToJob(res.data.createTag)
+ } else if (res.fetching === false && res.error) {
+ throw res.error
+ // console.log('Error on subscription: ' + res.error)
+ }
+ })
}
function addTagToJob(tag) {
pendingChange = tag.id
addTagsToJobMutation({ job: job.id, tagIds: [tag.id] })
- .then(res => {
- if (res.error)
- throw res.error
-
+ .subscribe(res => {
+ if (res.fetching === false && !res.error) {
jobTags = job.tags = res.data.addTagsToJob;
pendingChange = false;
- })
- .catch(err => console.error(err))
+ } else if (res.fetching === false && res.error) {
+ throw res.error
+ // console.log('Error on subscription: ' + res.error)
+ }
+ })
}
function removeTagFromJob(tag) {
pendingChange = tag.id
removeTagsFromJobMutation({ job: job.id, tagIds: [tag.id] })
- .then(res => {
- if (res.error)
- throw res.error
-
+ .subscribe(res => {
+ if (res.fetching === false && !res.error) {
jobTags = job.tags = res.data.removeTagsFromJob
pendingChange = false
- })
- .catch(err => console.error(err))
+ } else if (res.fetching === false && res.error) {
+ throw res.error
+ // console.log('Error on subscription: ' + res.error)
+ }
+ })
}
@@ -165,8 +172,7 @@
{#if newTagType && newTagName && isNewTag(newTagType, newTagName)}