Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

feat: realtime expanded form

mertmit1dc3a75bd64d
diff --git a/packages/nc-gui/composables/useExpandedFormStore.ts b/packages/nc-gui/composables/useExpandedFormStore.ts
index a4e1b15874..adcefbecd1 100644
--- a/packages/nc-gui/composables/useExpandedFormStore.ts
+++ b/packages/nc-gui/composables/useExpandedFormStore.ts
@@ -1,4 +1,12 @@
-import type { AuditType, ColumnType, DataPayload, MetaType, PlanLimitExceededDetailsType, TableType } from 'nocodb-sdk'
+import type {
+ AuditType,
+ ColumnType,
+ CommentPayload,
+ DataPayload,
+ MetaType,
+ PlanLimitExceededDetailsType,
+ TableType,
+} from 'nocodb-sdk'
import {
EventType,
PermissionEntity,
@@ -767,7 +775,8 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(
}
})
- const activeChannel = ref<string | null>(null)
+ const activeDataChannel = ref<string | null>(null)
+ const activeCommentChannel = ref<string | null>(null)
watch(
meta,
@@ -775,15 +784,21 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(
if (newMeta?.fk_workspace_id && newMeta?.base_id && newMeta?.id) {
if (oldMeta?.id && oldMeta.id === newMeta.id) return
- if (activeChannel.value) {
- $ncSocket.offMessage(activeChannel.value)
+ if (activeDataChannel.value) {
+ $ncSocket.offMessage(activeDataChannel.value)
+ }
+
+ if (activeCommentChannel.value) {
+ $ncSocket.offMessage(activeCommentChannel.value)
}
- activeChannel.value = `${EventType.DATA_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`
+ activeDataChannel.value = `${EventType.DATA_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`
+ activeCommentChannel.value = `${EventType.COMMENT_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`
- $ncSocket.subscribe(activeChannel.value)
+ $ncSocket.subscribe(activeDataChannel.value)
+ $ncSocket.subscribe(activeCommentChannel.value)
- $ncSocket.onMessage(activeChannel.value, (data: DataPayload) => {
+ $ncSocket.onMessage(activeDataChannel.value, (data: DataPayload) => {
const { id, action, payload } = data
const activePk = extractPkFromRow(row.value.row, meta.value?.columns as ColumnType[])
@@ -822,6 +837,32 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(
}
}
})
+
+ $ncSocket.onMessage(activeCommentChannel.value, (data: CommentPayload) => {
+ const { action, id, payload } = data
+
+ if (primaryKey.value && `${id}` === `${primaryKey.value}`) {
+ const commentId = payload.id
+ const user = baseUsers.value.find((u) => u.id === payload.created_by)
+ const finalPayload = {
+ ...payload,
+ created_display_name: user?.display_name ?? (user?.email ?? '').split('@')[0],
+ created_by_email: user?.email,
+ created_by_meta: user?.meta,
+ }
+
+ if (action === 'add') {
+ comments.value.push(finalPayload)
+ } else if (action === 'update') {
+ const index = comments.value.findIndex((comment) => comment.id === commentId)
+ if (index !== -1) {
+ comments.value[index] = finalPayload
+ }
+ } else if (action === 'delete') {
+ comments.value = comments.value.filter((comment) => comment.id !== commentId)
+ }
+ }
+ })
}
},
{ immediate: true },