Skip to content

Commit fbc5022

Browse files
committed
fix emits & cardID passing
1 parent 59fa63f commit fbc5022

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

packages/common-ui/src/components/CardHistoryViewer.vue

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,21 @@
44
<div v-if="loading">Loading...</div>
55
<div v-else-if="error" class="error-message">{{ error }}</div>
66
<div v-else>
7-
<v-data-table
8-
:headers="headers"
9-
:items="history"
10-
class="elevation-1"
11-
>
7+
<v-data-table :headers="headers" :items="history" class="elevation-1">
128
<template v-slot:item.hasNegativeInterval="{ item }">
13-
<v-chip
14-
:color="item.hasNegativeInterval ? 'error' : 'success'"
15-
:text-color="'white'"
16-
small
17-
>
9+
<v-chip :color="item.hasNegativeInterval ? 'error' : 'success'" :text-color="'white'" small>
1810
{{ item.hasNegativeInterval ? 'INVALID' : 'Valid' }}
1911
</v-chip>
2012
</template>
21-
13+
2214
<template v-slot:item.intervalFromPrevious="{ item }">
23-
<span
24-
:class="{ 'negative-interval': item.hasNegativeInterval }"
25-
>
15+
<span :class="{ 'negative-interval': item.hasNegativeInterval }">
2616
{{ item.intervalFromPrevious !== undefined ? item.intervalFromPrevious : '-' }}
2717
</span>
2818
</template>
2919

3020
<template v-slot:item.formattedTimeStamp="{ item }">
31-
<span
32-
:class="{ 'invalid-timestamp': item.hasNegativeInterval }"
33-
>
21+
<span :class="{ 'invalid-timestamp': item.hasNegativeInterval }">
3422
{{ item.formattedTimeStamp }}
3523
</span>
3624
</template>
@@ -108,28 +96,28 @@ export default defineComponent({
10896
try {
10997
const cardHistoryID = getCardHistoryID(this.courseId, this.cardId);
11098
const historyDoc: CardHistory<CardRecord> = await this.userDB.get(cardHistoryID);
111-
99+
112100
// Sort records by timestamp and format them
113-
const sortedRecords = [...historyDoc.records].sort((a, b) =>
114-
moment(a.timeStamp).valueOf() - moment(b.timeStamp).valueOf()
101+
const sortedRecords = [...historyDoc.records].sort(
102+
(a, b) => moment(a.timeStamp).valueOf() - moment(b.timeStamp).valueOf()
115103
);
116-
104+
117105
this.history = sortedRecords.map((record, index) => {
118106
const currentTime = moment(record.timeStamp);
119107
const formatted: FormattedRecord = {
120108
...record,
121109
formattedTimeStamp: currentTime.format('YYYY-MM-DD HH:mm:ss'),
122110
timeSpentSeconds: Math.round(record.timeSpent / 1000),
123111
};
124-
112+
125113
// Calculate interval from previous record
126114
if (index > 0) {
127115
const previousTime = moment(sortedRecords[index - 1].timeStamp);
128116
const intervalMinutes = currentTime.diff(previousTime, 'minutes', true);
129117
formatted.intervalFromPrevious = Math.round(intervalMinutes * 100) / 100;
130118
formatted.hasNegativeInterval = intervalMinutes < 0;
131119
}
132-
120+
133121
return formatted;
134122
});
135123
} catch (e) {

packages/common-ui/src/components/CardSearchResults.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ interface CardWithCourse extends CardData {
2929
export default defineComponent({
3030
name: 'CardSearchResults',
3131
emits: {
32-
'card-selected': (cardId: string, courseId: string) =>
33-
typeof cardId === 'string' && typeof courseId === 'string'
32+
'card-selected': (payload: { cardId: string; courseId: string }) =>
33+
typeof payload.cardId === 'string' && typeof payload.courseId === 'string'
3434
},
3535
props: {
3636
query: {
@@ -107,7 +107,7 @@ export default defineComponent({
107107
},
108108
109109
selectCard(card: CardWithCourse) {
110-
this.$emit('card-selected', card._id, card.courseId);
110+
this.$emit('card-selected', { cardId: card._id, courseId: card.courseId });
111111
},
112112
},
113113
});

0 commit comments

Comments
 (0)