Skip to content

Commit fd5a77b

Browse files
fix: Trigger animation on success of delete
1 parent ff64cb0 commit fd5a77b

File tree

5 files changed

+22
-58
lines changed

5 files changed

+22
-58
lines changed

src/components/NotificationCard.vue

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@
3737
<script setup lang="ts">
3838
import type { CSSProperties } from 'vue';
3939
import { defineProps, watch, ref } from 'vue';
40+
import PubSub from 'pubsub-js';
4041
4142
import type { NotificationCardProps } from '../types';
4243
import { generateElapsedTimeText } from '../utils/commonUtils';
44+
import { eventTypes, events } from '../utils/constants';
4345
import CloseIcon from './CloseIcon.vue';
4446
import TimerIcon from './TimerIcon.vue';
47+
import useSiren from '../composables/useSiren';
4548
import defaultAvatarDark from '../assets/dark/defaultAvatarDark.png';
4649
import defaultAvatarLight from '../assets/light/defaultAvatarLight.png';
4750
4851
import '../styles/card.css';
49-
import useSiren from '../composables/useSiren';
5052
5153
const props = defineProps<NotificationCardProps>();
5254
@@ -60,14 +62,19 @@ let cardContainerStyle: CSSProperties;
6062
6163
const defaultAvatar: string = props?.darkMode ? defaultAvatarDark : defaultAvatarLight;
6264
63-
const handleDelete = (event: MouseEvent | KeyboardEvent) => {
64-
deleteAnimation.value = 'siren-sdk-delete-animation';
65+
const handleDelete = async (event: MouseEvent | KeyboardEvent): Promise<void> => {
66+
event.stopPropagation();
67+
const isSuccess = await props.deleteById(props.notification.id, false);
68+
69+
if (isSuccess) {
70+
deleteAnimation.value = 'siren-sdk-delete-animation';
6571
6672
setTimeout(() => {
67-
props.deleteById(props.notification.id);
68-
}, 200);
73+
const payload = { id: props.notification.id, action: eventTypes.DELETE_ITEM };
6974
70-
event.stopPropagation();
75+
PubSub.publish(events.NOTIFICATION_LIST_EVENT, JSON.stringify(payload));
76+
}, 200);
77+
}
7178
};
7279
7380
const handleNotificationCardClick = () => {

src/components/SirenPanel.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,13 @@ const triggerOnError = computed(
141141
}
142142
);
143143
144-
const deleteNotificationById = computed(() => async (id: string) => {
145-
try {
146-
const response = await deleteById(id);
144+
const deleteNotificationById = async (id: string, shouldUpdateList: boolean): Promise<boolean> => {
145+
const response = await deleteById(id, shouldUpdateList);
147146
148147
if (response) triggerOnError.value(response);
149-
} catch (err) {
150-
// TODO: handle error
151-
}
152-
});
148+
149+
return !!response?.data;
150+
};
153151
154152
const notificationSubscriber = async (_type: string, dataString: string) => {
155153
const data = await JSON.parse(dataString);

src/composables/useSiren.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ const useSiren = () => {
4646
return { error: errorMap.SIREN_OBJECT_NOT_FOUND };
4747
};
4848

49-
const deleteById = async (id: string) => {
49+
const deleteById = async (id: string, shouldUpdateList: boolean = true) => {
5050
if (siren.value)
5151
if (id?.length > 0) {
5252
const response = await siren.value?.deleteById(id);
5353

54-
if (response && response.data) {
54+
if (response?.data && shouldUpdateList) {
5555
const payload = { id, action: eventTypes.DELETE_ITEM };
5656

5757
PubSub.publish(

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export type NotificationCardProps = {
233233
cardProps: SirenInboxProps['cardProps'];
234234
onCardClick?: SirenInboxProps['onCardClick'];
235235
styles: SirenStyleProps;
236-
deleteById: (id: string) => void;
236+
deleteById: (id: string, shouldUpdateList: boolean) => Promise<boolean>
237237
darkMode: boolean;
238238
};
239239

tests/components/__snapshots__/sirenPanel.spec.ts.snap

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -874,27 +874,7 @@ VueWrapper {
874874
"containerClassNames": "siren-sdk-content-container",
875875
"deleteByDate": [Function],
876876
"deleteById": [Function],
877-
"deleteNotificationById": ComputedRefImpl {
878-
"__v_isReadonly": true,
879-
"__v_isRef": true,
880-
"_cacheable": true,
881-
"_setter": [Function],
882-
"dep": undefined,
883-
"effect": ReactiveEffect {
884-
"_depsLength": 0,
885-
"_dirtyLevel": 4,
886-
"_runnings": 0,
887-
"_shouldSchedule": false,
888-
"_trackId": 0,
889-
"active": true,
890-
"computed": [Circular],
891-
"deps": [],
892-
"fn": [Function],
893-
"scheduler": undefined,
894-
"trigger": [Function],
895-
},
896-
"getter": [Function],
897-
},
877+
"deleteNotificationById": [Function],
898878
"error": RefImpl {
899879
"__v_isRef": true,
900880
"__v_isShallow": false,
@@ -1923,27 +1903,6 @@ VueWrapper {
19231903
"cleanups": [],
19241904
"detached": true,
19251905
"effects": [
1926-
ReactiveEffect {
1927-
"_depsLength": 0,
1928-
"_dirtyLevel": 4,
1929-
"_runnings": 0,
1930-
"_shouldSchedule": false,
1931-
"_trackId": 0,
1932-
"active": true,
1933-
"computed": ComputedRefImpl {
1934-
"__v_isReadonly": true,
1935-
"__v_isRef": true,
1936-
"_cacheable": true,
1937-
"_setter": [Function],
1938-
"dep": undefined,
1939-
"effect": [Circular],
1940-
"getter": [Function],
1941-
},
1942-
"deps": [],
1943-
"fn": [Function],
1944-
"scheduler": undefined,
1945-
"trigger": [Function],
1946-
},
19471906
ReactiveEffect {
19481907
"_depsLength": 0,
19491908
"_dirtyLevel": 4,

0 commit comments

Comments
 (0)