|
20 | 20 | <script lang="ts"> |
21 | 21 | import { goto, invalidate } from '$app/navigation'; |
22 | 22 | import { Dependencies } from '$lib/constants'; |
23 | | - import { realtime, sdk } from '$lib/stores/sdk'; |
| 23 | + import { type RealtimeResponse, realtime, sdk } from '$lib/stores/sdk'; |
24 | 24 | import { onMount } from 'svelte'; |
25 | 25 | import { |
26 | 26 | table, |
|
66 | 66 |
|
67 | 67 | import IndexesSuggestions from '../(suggestions)/indexes.svelte'; |
68 | 68 | import { showIndexesSuggestions, tableColumnSuggestions } from '../(suggestions)'; |
69 | | - import type { RealtimeResponseEvent } from '@appwrite.io/console'; |
70 | 69 |
|
71 | 70 | let editRow: EditRow; |
72 | 71 | let editRelatedRow: EditRelatedRow; |
|
83 | 82 | */ |
84 | 83 | let isWaterfallFromFaker = false; |
85 | 84 |
|
86 | | - let columnCreationHandler: ((response: RealtimeResponseEvent<unknown>) => void) | null = null; |
| 85 | + let columnCreationHandler: ((response: RealtimeResponse) => void) | null = null; |
87 | 86 |
|
88 | 87 | onMount(() => { |
89 | 88 | expandTabs.set(preferences.getKey('tableHeaderExpanded', true)); |
90 | 89 |
|
91 | | - return realtime |
92 | | - .forProject(page.params.region, page.params.project) |
93 | | - .subscribe(['project', 'console'], (response) => { |
| 90 | + return realtime.forProject(page.params.region, ['project', 'console'], (response) => { |
| 91 | + if ( |
| 92 | + response.events.includes('databases.*.tables.*.columns.*') || |
| 93 | + response.events.includes('databases.*.tables.*.indexes.*') |
| 94 | + ) { |
| 95 | + if (isWaterfallFromFaker) { |
| 96 | + columnCreationHandler?.(response); |
| 97 | + } |
| 98 | +
|
| 99 | + // don't invalidate when - |
| 100 | + // 1. from faker |
| 101 | + // 2. ai columns creation |
| 102 | + // 3. ai indexes creation |
94 | 103 | if ( |
95 | | - response.events.includes('databases.*.tables.*.columns.*') || |
96 | | - response.events.includes('databases.*.tables.*.indexes.*') |
| 104 | + !isWaterfallFromFaker && |
| 105 | + !$showIndexesSuggestions && |
| 106 | + !$tableColumnSuggestions.table |
97 | 107 | ) { |
98 | | - if (isWaterfallFromFaker) { |
99 | | - columnCreationHandler?.(response); |
100 | | - } |
101 | | -
|
102 | | - // don't invalidate when - |
103 | | - // 1. from faker |
104 | | - // 2. ai columns creation |
105 | | - // 3. ai indexes creation |
106 | | - if ( |
107 | | - !isWaterfallFromFaker && |
108 | | - !$showIndexesSuggestions && |
109 | | - !$tableColumnSuggestions.table |
110 | | - ) { |
111 | | - invalidate(Dependencies.TABLE); |
112 | | - } |
| 108 | + invalidate(Dependencies.TABLE); |
113 | 109 | } |
114 | | - }); |
| 110 | + } |
| 111 | + }); |
115 | 112 | }); |
116 | 113 |
|
117 | 114 | // TODO: use route ids instead of pathname |
|
268 | 265 | const availableColumns = new Set<string>(); |
269 | 266 | const waitPromise = new Promise<void>((resolve) => (resolvePromise = resolve)); |
270 | 267 |
|
271 | | - columnCreationHandler = (response) => { |
| 268 | + columnCreationHandler = (response: RealtimeResponse) => { |
272 | 269 | const { events, payload } = response; |
273 | 270 |
|
274 | 271 | if ( |
|
0 commit comments