feat: improve subscription
This commit is contained in:
parent
b1a8bbe760
commit
341b8d2045
@ -33,7 +33,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {computed, shallowRef, type PropType} from 'vue'
|
import {computed, shallowReactive} from 'vue'
|
||||||
import {useI18n} from 'vue-i18n'
|
import {useI18n} from 'vue-i18n'
|
||||||
|
|
||||||
import BaseButton from '@/components/base/BaseButton.vue'
|
import BaseButton from '@/components/base/BaseButton.vue'
|
||||||
@ -46,28 +46,23 @@ import type {ISubscription} from '@/modelTypes/ISubscription'
|
|||||||
import {success} from '@/message'
|
import {success} from '@/message'
|
||||||
import type { IconProp } from '@fortawesome/fontawesome-svg-core'
|
import type { IconProp } from '@fortawesome/fontawesome-svg-core'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = withDefaults(defineProps<{
|
||||||
entity: String as ISubscription['entity'],
|
entity: ISubscription['entity'],
|
||||||
entityId: Number,
|
entityId: number,
|
||||||
isButton: {
|
isButton?: boolean,
|
||||||
type: Boolean,
|
modelValue?: ISubscription,
|
||||||
default: true,
|
type?: 'button' | 'dropdown',
|
||||||
},
|
}>(), {
|
||||||
modelValue: {
|
isButton: true,
|
||||||
type: Object as PropType<ISubscription>,
|
modelValue: null,
|
||||||
default: null,
|
type: 'button',
|
||||||
},
|
|
||||||
type: {
|
|
||||||
type: String as PropType<'button' | 'dropdown' | 'null'>,
|
|
||||||
default: 'button',
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
const subscriptionEntity = computed<string | null>(() => props.modelValue?.entity ?? null)
|
const subscriptionEntity = computed<string | null>(() => props.modelValue?.entity ?? null)
|
||||||
|
|
||||||
const subscriptionService = shallowRef(new SubscriptionService())
|
const subscriptionService = shallowReactive(new SubscriptionService())
|
||||||
|
|
||||||
const {t} = useI18n({useScope: 'global'})
|
const {t} = useI18n({useScope: 'global'})
|
||||||
|
|
||||||
@ -77,8 +72,8 @@ const tooltipText = computed(() => {
|
|||||||
return t('task.subscription.subscribedTaskThroughParentProject')
|
return t('task.subscription.subscribedTaskThroughParentProject')
|
||||||
}
|
}
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (props.entity) {
|
switch (props.entity) {
|
||||||
case 'project':
|
case 'project':
|
||||||
@ -115,7 +110,7 @@ async function subscribe() {
|
|||||||
entity: props.entity,
|
entity: props.entity,
|
||||||
entityId: props.entityId,
|
entityId: props.entityId,
|
||||||
})
|
})
|
||||||
await subscriptionService.value.create(subscription)
|
await subscriptionService.create(subscription)
|
||||||
emit('update:modelValue', subscription)
|
emit('update:modelValue', subscription)
|
||||||
|
|
||||||
let message = ''
|
let message = ''
|
||||||
@ -135,7 +130,7 @@ async function unsubscribe() {
|
|||||||
entity: props.entity,
|
entity: props.entity,
|
||||||
entityId: props.entityId,
|
entityId: props.entityId,
|
||||||
})
|
})
|
||||||
await subscriptionService.value.delete(subscription)
|
await subscriptionService.delete(subscription)
|
||||||
emit('update:modelValue', null)
|
emit('update:modelValue', null)
|
||||||
|
|
||||||
let message = ''
|
let message = ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user