oneie 3.6.6 → 3.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/agent-backend.md +83 -0
- package/.claude/agents/agent-designer.md +97 -0
- package/.claude/agents/agent-director.md +118 -7
- package/.claude/agents/agent-documenter.md +93 -0
- package/.claude/agents/agent-frontend.md +96 -0
- package/.claude/agents/agent-ops.md +182 -25
- package/.claude/agents/agent-problem-solver.md +166 -0
- package/.claude/agents/agent-quality.md +127 -0
- package/.claude/commands/build.md +293 -0
- package/.claude/commands/cascade.md +231 -127
- package/.claude/commands/mcp-toggle.md +93 -0
- package/.claude/commands/onboard.md +179 -0
- package/.claude/commands/one.md +236 -516
- package/.claude/commands/plan.md +394 -80
- package/.claude/commands/release.md +41 -19
- package/.claude/commands/server.md +335 -0
- package/.claude/hooks/root-cleanup.py +75 -0
- package/.claude/skills/INDEX.md +523 -0
- package/.claude/skills/REGISTRY.md +529 -0
- package/.claude/skills/agent-backend-create-mutation.md +319 -0
- package/.claude/skills/agent-designer-create-wireframe.md +341 -0
- package/.claude/skills/agent-frontend-create-page.md +413 -0
- package/.claude/skills/agents/README.md +238 -0
- package/dist/clone-web.js +1 -1
- package/dist/clone-web.js.map +1 -1
- package/folders.yaml +1 -1
- package/one/.obsidian/workspace.json +38 -38
- package/one/connections/api/queries-reference.md +842 -0
- package/one/connections/api-reference.md +1011 -0
- package/one/connections/integration-examples.md +875 -0
- package/one/connections/integration-guide.md +869 -0
- package/one/connections/integration-phase2.md +736 -0
- package/one/events/API_ROUTES_FIXES_SUMMARY.md +262 -0
- package/one/events/ASTRO-INTEGRATION-EXAMPLES.md +636 -0
- package/one/events/BEFORE_AFTER_COMPARISON.md +960 -0
- package/one/events/CONNECTIONS_DEMO.md +501 -0
- package/one/events/DELIVERABLES.md +432 -0
- package/one/events/DEMO-GROUPS-PAGE.md +392 -0
- package/one/events/DEMO-TESTING-SUMMARY.md +518 -0
- package/one/events/DEMO_COMPONENTS.md +487 -0
- package/one/events/DEMO_HOOKS_INDEX.md +334 -0
- package/one/events/DEMO_INFRASTRUCTURE.md +905 -0
- package/one/events/DEMO_INFRASTRUCTURE_SUMMARY.md +570 -0
- package/one/events/DEMO_INTEGRATION_CHECKLIST.md +431 -0
- package/one/events/DEMO_QUICK_REFERENCE.md +441 -0
- package/one/events/DEMO_SETUP.md +476 -0
- package/one/events/EFFECT_TS_API_PATTERN.md +478 -0
- package/one/events/GROUPS_DEMO_IMPLEMENTATION.md +414 -0
- package/one/events/HOOKS-DEMO.md +441 -0
- package/one/events/ONTOLOGY-HOOKS-README.md +700 -0
- package/one/events/ONTOLOGY-INTEGRATION-MANIFEST.md +365 -0
- package/one/events/QA-CHECKLIST.md +674 -0
- package/one/events/QUICK-START-ONTOLOGY.md +408 -0
- package/one/events/SEARCH_DEMO_CODE_REFERENCE.md +639 -0
- package/one/events/SEARCH_DEMO_DELIVERY.md +415 -0
- package/one/events/SEARCH_DEMO_SUMMARY.md +303 -0
- package/one/events/SEARCH_DEMO_VISUAL_GUIDE.md +381 -0
- package/one/events/TEST-PLAN-INDEX.md +346 -0
- package/one/events/TEST-PLAN.md +1417 -0
- package/one/events/TESTING-DELIVERY.txt +372 -0
- package/one/events/TRANSITIONS-QUICK-START.md +141 -0
- package/one/events/TYPESCRIPT_FIXES.md +152 -0
- package/one/events/TYPESCRIPT_FIXES_COMPLETE.txt +412 -0
- package/one/events/TYPESCRIPT_FIXES_INDEX.md +341 -0
- package/one/events/VIEW-TRANSITIONS.md +428 -0
- package/one/events/backend-integration-tests.md +606 -0
- package/one/events/backend-structure-diagram.txt +393 -0
- package/one/events/backend-structure-summary.txt +269 -0
- package/one/events/cloudflare-pages-infrastructure-setup.md +264 -0
- package/one/events/convex-analysis-index.md +304 -0
- package/one/events/convex-structure-analysis.md +700 -0
- package/one/events/design-spec-complete.md +208 -0
- package/one/events/ontology-test-examples.md +562 -0
- package/one/events/phase1-backend-implementation-complete.md +518 -0
- package/one/events/test-dashboard.md +345 -0
- package/one/events/test-index.md +361 -0
- package/one/events/test-report-ontology.md +582 -0
- package/one/events/testing-summary.md +344 -0
- package/one/groups/features.md +2878 -0
- package/one/groups/strategy copy.md +869 -0
- package/one/knowledge/backend-api-reference.md +710 -0
- package/one/knowledge/documentation-summary.md +285 -0
- package/one/knowledge/lessons-learned.md +294 -4
- package/one/knowledge/ontology-visual-guide.md +360 -0
- package/one/knowledge/ontology.md +9 -17
- package/one/things/demo-accessibility-animations.md +999 -0
- package/one/things/demo-components.md +1304 -0
- package/one/things/demo-design-summary.md +629 -0
- package/one/things/demo-design-system.md +919 -0
- package/one/things/demo-page-layouts.md +989 -0
- package/one/things/designs/accessibility-audit.md +790 -0
- package/one/things/designs/component-specifications.md +757 -0
- package/one/things/designs/design-overview.md +318 -0
- package/one/things/designs/design-tokens.md +414 -0
- package/one/things/designs/wireframes-dashboard.md +653 -0
- package/one/things/docs/api-requests.md +923 -0
- package/one/things/features/0 All Features.md +2 -0
- package/one/things/implementation/backend-guide.md +412 -0
- package/one/things/plans/2-backend-agnostic-frontend.md +11 -8
- package/one/things/plans/ai-elements.md +1259 -0
- package/one/things/plans/ai-integration.md +947 -0
- package/one/things/plans/ai-sdk.md +761 -0
- package/one/things/plans/app.md +1 -1
- package/one/things/plans/architecture-summary.md +283 -0
- package/one/things/plans/async-ai-agents.md +215 -0
- package/one/things/plans/backend-agnostic-frontend.md +11 -6
- package/one/things/plans/backend-cleanup-quickstart.md +346 -0
- package/one/things/plans/backend-ontology-conformance.md +416 -0
- package/one/things/plans/backend-status.md +541 -0
- package/one/things/plans/backend-structure.md +799 -0
- package/one/things/plans/backend-target-structure.md +438 -0
- package/one/things/plans/backend.md +1133 -0
- package/one/things/plans/better-auth-any-backend.md +11 -11
- package/one/things/plans/cli-updates-required.md +280 -0
- package/one/things/plans/complete-step-by-step.md +1302 -0
- package/one/things/plans/convex-agents.md +1005 -0
- package/one/things/plans/deployment-architecture.md +426 -0
- package/one/things/plans/development-plan.md +1220 -0
- package/one/things/plans/effect.md +808 -48
- package/one/things/plans/integrate-frontend-and-backend.md +579 -0
- package/one/things/plans/mcp-clear-context-prompt.md +60 -0
- package/one/things/plans/mcp-simple.md +228 -0
- package/one/things/plans/one.md +8 -7
- package/one/things/plans/ontology-6-dimensions.md +20 -14
- package/one/things/plans/quick-wins.md +1273 -0
- package/one/things/plans/readme-backend-cleanup.md +361 -0
- package/one/things/plans/separate-demo.md +830 -0
- package/one/things/plans/separate.md +3 -3
- package/one/things/plans/sequence.md +1897 -0
- package/one/things/plans/sync-checklist.md +321 -0
- package/one/things/plans/unified-implementation-plan.md +3 -3
- package/one/things/plans/update-demos.md +513 -0
- package/package.json +1 -1
- package/.claude/agents/backend-specialist.md +0 -169
- package/.claude/agents/designer.md +0 -216
- package/.claude/agents/frontend-specialist.md +0 -236
- package/.claude/commands/done.md +0 -35
- package/.claude/commands/infer.md +0 -138
- package/.claude/commands/next.md +0 -53
- package/.claude/commands/one copy.md +0 -565
- package/.claude/commands/one-template.md +0 -106
- package/.claude/commands/one-v1.md +0 -609
- package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
- package/one/groups/nine-padel-customers.md +0 -138
- package/one/groups/nine-padel-data-structure.md +0 -167
- package/one/groups/nine-padel-ontology-specification.md +0 -359
- package/one/groups/nine-padel-ontology.md +0 -143
- package/one/groups/nine-padel-strategy.md +0 -234
- package/one/groups/nine-padel.md +0 -211
- package/one/groups/nine-padle-contents.baked.md +0 -1252
- package/one/groups/nine-padle-contents.md +0 -6
- package/one/things/features/1-1-agent-prompts/design.md +0 -470
- package/one/things/features/1-1-agent-prompts/tests.md +0 -264
- package/one/things/features/1-2-yaml-orchestrator/design.md +0 -497
- package/one/things/features/1-2-yaml-orchestrator/tests.md +0 -227
- package/one/things/features/1-3-event-coordination/design.md +0 -544
- package/one/things/features/1-3-event-coordination/tests.md +0 -223
- package/one/things/features/1-4-knowledge-management/design.md +0 -609
- package/one/things/features/1-4-knowledge-management/tests.md +0 -195
- package/one/things/features/1-5-quality-loops/design.md +0 -797
- package/one/things/features/1-5-quality-loops/tests.md +0 -212
- package/one/things/features/1-6-numbering-structure/design.md +0 -610
- package/one/things/features/1-6-numbering-structure/tests.md +0 -213
- package/one/things/features/dataprovider-interface/1-tests.md +0 -1522
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
# Demo Infrastructure Implementation Guide
|
|
2
|
+
|
|
3
|
+
Complete reference for demo page hooks, stores, and utilities supporting Infer 1-20.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The demo infrastructure provides a complete set of TypeScript hooks and utilities for demo pages to:
|
|
8
|
+
|
|
9
|
+
1. **Monitor Backend Connection** - Real-time health checks with automatic reconnection
|
|
10
|
+
2. **Fetch Data Efficiently** - React Query integration with caching and refetching
|
|
11
|
+
3. **Manage Mutations** - Create, update, delete operations with optimistic updates
|
|
12
|
+
4. **Synchronize Filters** - URL-based filter state with debounced search
|
|
13
|
+
5. **Centralize State** - Nanostores for shared global state
|
|
14
|
+
|
|
15
|
+
## Files Created (Infer 1-20)
|
|
16
|
+
|
|
17
|
+
### Hook Files
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
/web/src/hooks/demo/
|
|
21
|
+
├── useBackendConnection.ts (303 lines) - Connection monitoring
|
|
22
|
+
├── useDemoData.ts (289 lines) - HTTP data fetching
|
|
23
|
+
├── useDemoMutation.ts (310 lines) - Create/update/delete operations
|
|
24
|
+
├── useDemoFilters.ts (380 lines) - Filter state management
|
|
25
|
+
├── useDebounce.ts (113 lines) - Utility for debouncing
|
|
26
|
+
├── index.ts (69 lines) - Central exports
|
|
27
|
+
└── README.md (800+ lines) - Complete documentation
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Store Files
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
/web/src/stores/
|
|
34
|
+
└── demo.ts (420 lines) - Global demo state
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Hook Index Update
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
/web/src/hooks/index.ts (+50 lines) - Added demo exports
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Total: 1,834 lines of fully typed, documented code**
|
|
44
|
+
|
|
45
|
+
## Architecture
|
|
46
|
+
|
|
47
|
+
### Hook Layers
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
┌─────────────────────────────────────────────┐
|
|
51
|
+
│ React Components (Demo Pages) │
|
|
52
|
+
├─────────────────────────────────────────────┤
|
|
53
|
+
│ │
|
|
54
|
+
│ useBackendConnection() │
|
|
55
|
+
│ useDemoData() │
|
|
56
|
+
│ useDemoMutation() │
|
|
57
|
+
│ useDemoFilters() │
|
|
58
|
+
│ useDebounce() │
|
|
59
|
+
│ │
|
|
60
|
+
├─────────────────────────────────────────────┤
|
|
61
|
+
│ React Query + Nanostores (State) │
|
|
62
|
+
├─────────────────────────────────────────────┤
|
|
63
|
+
│ HTTP API Calls (/http/*) │
|
|
64
|
+
├─────────────────────────────────────────────┤
|
|
65
|
+
│ Backend (Convex or other providers) │
|
|
66
|
+
└─────────────────────────────────────────────┘
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Data Flow
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
Component
|
|
73
|
+
↓
|
|
74
|
+
useDemo* Hook (React Query)
|
|
75
|
+
↓
|
|
76
|
+
Query/Mutation Function
|
|
77
|
+
↓
|
|
78
|
+
HTTP API Call (/http/...)
|
|
79
|
+
↓
|
|
80
|
+
Backend Processing
|
|
81
|
+
↓
|
|
82
|
+
Response
|
|
83
|
+
↓
|
|
84
|
+
Cache Update (Nanostores)
|
|
85
|
+
↓
|
|
86
|
+
Component Re-render
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Hook Guide
|
|
90
|
+
|
|
91
|
+
### 1. useBackendConnection
|
|
92
|
+
|
|
93
|
+
**Purpose:** Monitor connection status and manage reconnection
|
|
94
|
+
|
|
95
|
+
**Key Features:**
|
|
96
|
+
- Real-time connection status: 'connecting' | 'connected' | 'disconnected' | 'error'
|
|
97
|
+
- Automatic latency measurement
|
|
98
|
+
- Exponential backoff reconnection
|
|
99
|
+
- 30-second health check interval
|
|
100
|
+
- Max 5 reconnection attempts
|
|
101
|
+
|
|
102
|
+
**Usage:**
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
import { useBackendConnection } from '@/hooks/demo';
|
|
106
|
+
|
|
107
|
+
function StatusBar() {
|
|
108
|
+
const { status, latency, isConnected, reconnect } = useBackendConnection();
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div className={isConnected ? 'text-green-500' : 'text-red-500'}>
|
|
112
|
+
{status} ({latency}ms)
|
|
113
|
+
{!isConnected && <button onClick={reconnect}>Reconnect</button>}
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**API:**
|
|
120
|
+
- `status: ConnectionStatus` - Current connection state
|
|
121
|
+
- `latency: number` - Round-trip time in ms
|
|
122
|
+
- `isConnected: boolean` - Convenience boolean
|
|
123
|
+
- `isDisconnected: boolean` - Convenience boolean
|
|
124
|
+
- `isError: boolean` - Error state
|
|
125
|
+
- `reconnect(): Promise<void>` - Manual reconnection
|
|
126
|
+
- `reset(): void` - Reset connection state
|
|
127
|
+
- `lastChecked: number` - Last check timestamp
|
|
128
|
+
- `reconnectAttempts: number` - Current attempt count
|
|
129
|
+
|
|
130
|
+
**Tech Stack:**
|
|
131
|
+
- Plain fetch API with 5-second timeout
|
|
132
|
+
- Performance API for latency measurement
|
|
133
|
+
- exponential backoff: delay = 1000 * 2^attemptNumber
|
|
134
|
+
|
|
135
|
+
**Configuration Constants:**
|
|
136
|
+
- `BACKEND_URL` = 'https://veracious-marlin-319.convex.cloud'
|
|
137
|
+
- `HEALTH_CHECK_INTERVAL` = 30 seconds
|
|
138
|
+
- `MAX_RECONNECT_ATTEMPTS` = 5
|
|
139
|
+
- `INITIAL_RECONNECT_DELAY` = 1 second
|
|
140
|
+
|
|
141
|
+
### 2. useDemoData
|
|
142
|
+
|
|
143
|
+
**Purpose:** Fetch and cache data from HTTP API endpoints
|
|
144
|
+
|
|
145
|
+
**Key Features:**
|
|
146
|
+
- React Query integration for efficient caching
|
|
147
|
+
- Stale-while-revalidate pattern
|
|
148
|
+
- Automatic refetching on interval
|
|
149
|
+
- Pagination support
|
|
150
|
+
- Retry logic (2 attempts with exponential backoff)
|
|
151
|
+
- 5-minute default cache duration
|
|
152
|
+
- Batch fetching support
|
|
153
|
+
|
|
154
|
+
**Usage:**
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { useDemoData } from '@/hooks/demo';
|
|
158
|
+
|
|
159
|
+
function ThingsList() {
|
|
160
|
+
const { data: things, loading, error, refetch } = useDemoData('things', {
|
|
161
|
+
type: 'course',
|
|
162
|
+
status: 'published',
|
|
163
|
+
limit: 20,
|
|
164
|
+
offset: 0,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
if (loading) return <Skeleton />;
|
|
168
|
+
if (error) return <ErrorAlert error={error} />;
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div>
|
|
172
|
+
{things?.map(thing => (
|
|
173
|
+
<ThingCard key={thing._id} thing={thing} />
|
|
174
|
+
))}
|
|
175
|
+
<button onClick={refetch}>Refresh</button>
|
|
176
|
+
</div>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**API:**
|
|
182
|
+
- `data: T[] | null` - Fetched items
|
|
183
|
+
- `loading: boolean` - Is loading
|
|
184
|
+
- `error: Error | null` - Error object
|
|
185
|
+
- `refetch(): Promise<void>` - Force refresh
|
|
186
|
+
- `isRefetching: boolean` - Background refetch in progress
|
|
187
|
+
- `hasNextPage: boolean` - More results exist
|
|
188
|
+
- `hasPreviousPage: boolean` - Previous page exists
|
|
189
|
+
|
|
190
|
+
**Query Parameters:**
|
|
191
|
+
- `groupId?: string` - Filter by group
|
|
192
|
+
- `type?: string` - Entity type
|
|
193
|
+
- `status?: string` - Status filter
|
|
194
|
+
- `search?: string` - Full-text search
|
|
195
|
+
- `limit?: number` - Results per page (default: 20)
|
|
196
|
+
- `offset?: number` - Pagination offset
|
|
197
|
+
- `enabled?: boolean` - Enable/disable query
|
|
198
|
+
- `refetchInterval?: number` - Auto-refetch interval (ms)
|
|
199
|
+
- `staleTime?: number` - Cache validity (ms, default: 5min)
|
|
200
|
+
|
|
201
|
+
**Caching:**
|
|
202
|
+
- 5-minute default TTL
|
|
203
|
+
- Query key based on resource + all options
|
|
204
|
+
- Automatic invalidation on mutation
|
|
205
|
+
- Manual clear with `clearDemoCache()` or `clearDemoCacheForResource()`
|
|
206
|
+
|
|
207
|
+
**Batch Fetch:**
|
|
208
|
+
|
|
209
|
+
```tsx
|
|
210
|
+
import { fetchDemoBatch } from '@/hooks/demo';
|
|
211
|
+
|
|
212
|
+
const data = await fetchDemoBatch([
|
|
213
|
+
{ resource: 'things', options: { type: 'course' } },
|
|
214
|
+
{ resource: 'connections' },
|
|
215
|
+
{ resource: 'events' },
|
|
216
|
+
]);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 3. useDemoMutation
|
|
220
|
+
|
|
221
|
+
**Purpose:** Create, update, delete entities with automatic cache management
|
|
222
|
+
|
|
223
|
+
**Key Features:**
|
|
224
|
+
- Automatic cache invalidation
|
|
225
|
+
- Optimistic updates with rollback
|
|
226
|
+
- Toast notifications (success/error)
|
|
227
|
+
- Configurable messages
|
|
228
|
+
- Loading states
|
|
229
|
+
- Error recovery
|
|
230
|
+
|
|
231
|
+
**Create Mutation:**
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
import { useDemoCreateMutation } from '@/hooks/demo';
|
|
235
|
+
|
|
236
|
+
function CreateThingForm() {
|
|
237
|
+
const { mutate: createThing, loading, error } = useDemoCreateMutation('things', {
|
|
238
|
+
onSuccess: (data) => {
|
|
239
|
+
console.log('Created:', data._id);
|
|
240
|
+
},
|
|
241
|
+
successMessage: 'Thing created successfully!',
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return (
|
|
245
|
+
<form onSubmit={(e) => {
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
createThing({
|
|
248
|
+
type: 'course',
|
|
249
|
+
name: 'My Course',
|
|
250
|
+
properties: { description: '...' }
|
|
251
|
+
});
|
|
252
|
+
}}>
|
|
253
|
+
<input name="name" />
|
|
254
|
+
<button disabled={loading}>{loading ? 'Creating...' : 'Create'}</button>
|
|
255
|
+
{error && <div>{error.message}</div>}
|
|
256
|
+
</form>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Update Mutation:**
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
import { useDemoUpdateMutation } from '@/hooks/demo';
|
|
265
|
+
|
|
266
|
+
const { mutate: updateThing } = useDemoUpdateMutation('things', {
|
|
267
|
+
onSuccess: () => toast.success('Updated!'),
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
await updateThing({ _id: thingId, name: 'New Name', status: 'published' });
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Delete Mutation:**
|
|
274
|
+
|
|
275
|
+
```tsx
|
|
276
|
+
import { useDemoDeleteMutation } from '@/hooks/demo';
|
|
277
|
+
|
|
278
|
+
const { mutate: deleteThing } = useDemoDeleteMutation('things');
|
|
279
|
+
|
|
280
|
+
await deleteThing(thingId);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**API:**
|
|
284
|
+
- `mutate(data): Promise<T>` - Execute mutation
|
|
285
|
+
- `loading: boolean` - Is loading
|
|
286
|
+
- `error: Error | null` - Error object
|
|
287
|
+
- `data: T | null` - Result
|
|
288
|
+
- `reset(): void` - Reset state
|
|
289
|
+
|
|
290
|
+
**Options:**
|
|
291
|
+
- `onSuccess?: (data: T) => Promise<void> | void`
|
|
292
|
+
- `onError?: (error: Error) => Promise<void> | void`
|
|
293
|
+
- `onMutate?: (data: any) => Promise<void> | void`
|
|
294
|
+
- `onSettled?: () => Promise<void> | void`
|
|
295
|
+
- `showSuccessToast?: boolean` (default: true)
|
|
296
|
+
- `showErrorToast?: boolean` (default: true)
|
|
297
|
+
- `successMessage?: string`
|
|
298
|
+
- `errorMessage?: string`
|
|
299
|
+
|
|
300
|
+
**HTTP Methods:**
|
|
301
|
+
- `POST /http/{resource}` - Create
|
|
302
|
+
- `PATCH /http/{resource}/{id}` - Update
|
|
303
|
+
- `DELETE /http/{resource}/{id}` - Delete
|
|
304
|
+
|
|
305
|
+
### 4. useDemoFilters
|
|
306
|
+
|
|
307
|
+
**Purpose:** Manage filter state with URL synchronization
|
|
308
|
+
|
|
309
|
+
**Key Features:**
|
|
310
|
+
- URL query parameter sync
|
|
311
|
+
- Shareable filter URLs
|
|
312
|
+
- Debounced search (300ms)
|
|
313
|
+
- Pagination support
|
|
314
|
+
- Multi-filter support
|
|
315
|
+
- Type-safe filter updates
|
|
316
|
+
|
|
317
|
+
**Usage:**
|
|
318
|
+
|
|
319
|
+
```tsx
|
|
320
|
+
import { useDemoFilters, useDemoData } from '@/hooks/demo';
|
|
321
|
+
|
|
322
|
+
function ThingsWithFilters() {
|
|
323
|
+
const {
|
|
324
|
+
filters,
|
|
325
|
+
search,
|
|
326
|
+
setSearch,
|
|
327
|
+
setType,
|
|
328
|
+
setStatus,
|
|
329
|
+
view,
|
|
330
|
+
setView,
|
|
331
|
+
debouncedSearch,
|
|
332
|
+
nextPage,
|
|
333
|
+
previousPage,
|
|
334
|
+
currentPage,
|
|
335
|
+
hasActiveFilters,
|
|
336
|
+
shareableUrl,
|
|
337
|
+
} = useDemoFilters();
|
|
338
|
+
|
|
339
|
+
const { data: things } = useDemoData('things', {
|
|
340
|
+
type: filters.type,
|
|
341
|
+
status: filters.status,
|
|
342
|
+
search: debouncedSearch,
|
|
343
|
+
limit: filters.limit,
|
|
344
|
+
offset: filters.offset,
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<div>
|
|
349
|
+
<input
|
|
350
|
+
placeholder="Search..."
|
|
351
|
+
value={search}
|
|
352
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
353
|
+
/>
|
|
354
|
+
|
|
355
|
+
<select value={filters.type || ''} onChange={(e) => setType(e.target.value || undefined)}>
|
|
356
|
+
<option value="">All Types</option>
|
|
357
|
+
<option value="course">Courses</option>
|
|
358
|
+
</select>
|
|
359
|
+
|
|
360
|
+
<select value={view} onChange={(e) => setView(e.target.value as any)}>
|
|
361
|
+
<option value="list">List</option>
|
|
362
|
+
<option value="grid">Grid</option>
|
|
363
|
+
<option value="graph">Graph</option>
|
|
364
|
+
</select>
|
|
365
|
+
|
|
366
|
+
{/* Render based on view */}
|
|
367
|
+
{view === 'list' && (
|
|
368
|
+
<ul>{things?.map(thing => <li key={thing._id}>{thing.name}</li>)}</ul>
|
|
369
|
+
)}
|
|
370
|
+
|
|
371
|
+
{/* Pagination */}
|
|
372
|
+
<button onClick={previousPage} disabled={currentPage === 1}>Previous</button>
|
|
373
|
+
<span>Page {currentPage}</span>
|
|
374
|
+
<button onClick={nextPage}>Next</button>
|
|
375
|
+
|
|
376
|
+
{/* Share */}
|
|
377
|
+
<a href={shareableUrl}>Share this view</a>
|
|
378
|
+
</div>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**API:**
|
|
384
|
+
- `filters: DemoFilters` - Current filters
|
|
385
|
+
- `search: string` - Raw search input
|
|
386
|
+
- `debouncedSearch: string` - 300ms debounced
|
|
387
|
+
- `view: ViewMode` - Current view mode
|
|
388
|
+
- `setFilters(updates): void`
|
|
389
|
+
- `setType(type): void`
|
|
390
|
+
- `setStatus(status): void`
|
|
391
|
+
- `setSearch(text): void`
|
|
392
|
+
- `setView(mode): void`
|
|
393
|
+
- `setPagination(limit, offset): void`
|
|
394
|
+
- `nextPage(): void`
|
|
395
|
+
- `previousPage(): void`
|
|
396
|
+
- `resetFilters(): void`
|
|
397
|
+
- `clearSearch(): void`
|
|
398
|
+
- `currentPage: number`
|
|
399
|
+
- `pageSize: number`
|
|
400
|
+
- `offset: number`
|
|
401
|
+
- `hasActiveFilters: boolean`
|
|
402
|
+
- `shareableUrl: string`
|
|
403
|
+
|
|
404
|
+
**URL Sync:**
|
|
405
|
+
|
|
406
|
+
Filters automatically sync to URL query parameters:
|
|
407
|
+
|
|
408
|
+
```
|
|
409
|
+
/demo/things?type=course&status=published&search=python&view=grid&limit=20&offset=0
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### 5. useDebounce
|
|
413
|
+
|
|
414
|
+
**Purpose:** Debounce values for search, filters, etc.
|
|
415
|
+
|
|
416
|
+
**Usage:**
|
|
417
|
+
|
|
418
|
+
```tsx
|
|
419
|
+
import { useDebounce } from '@/hooks/demo';
|
|
420
|
+
|
|
421
|
+
function SearchThings() {
|
|
422
|
+
const [search, setSearch] = useState('');
|
|
423
|
+
const debouncedSearch = useDebounce(search, 300);
|
|
424
|
+
|
|
425
|
+
const { data } = useDemoData('things', { search: debouncedSearch });
|
|
426
|
+
|
|
427
|
+
return (
|
|
428
|
+
<input
|
|
429
|
+
value={search}
|
|
430
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
431
|
+
placeholder="Search (debounced)..."
|
|
432
|
+
/>
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**API:**
|
|
438
|
+
- `useDebounce<T>(value: T, delay?: number): T`
|
|
439
|
+
- `debounce<T>(func: T, delay: number): (...args: Parameters<T>) => void`
|
|
440
|
+
- `createDebounce<T>(func: T, delay: number, options?): (...args: Parameters<T>) => void`
|
|
441
|
+
|
|
442
|
+
**Options for createDebounce:**
|
|
443
|
+
- `leading?: boolean` - Call on leading edge
|
|
444
|
+
- `trailing?: boolean` - Call on trailing edge (default: true)
|
|
445
|
+
- `maxWait?: number` - Maximum wait time
|
|
446
|
+
|
|
447
|
+
## Store Guide
|
|
448
|
+
|
|
449
|
+
### Global State Stores
|
|
450
|
+
|
|
451
|
+
Import from `@/stores/demo`:
|
|
452
|
+
|
|
453
|
+
```tsx
|
|
454
|
+
import {
|
|
455
|
+
$demoConnection,
|
|
456
|
+
$demoGroup,
|
|
457
|
+
$demoView,
|
|
458
|
+
$demoData,
|
|
459
|
+
$demoLoading,
|
|
460
|
+
$demoErrors,
|
|
461
|
+
$demoUI,
|
|
462
|
+
$demoStats,
|
|
463
|
+
$demoSelection,
|
|
464
|
+
selectThing,
|
|
465
|
+
updateDemoUI,
|
|
466
|
+
toggleSidebar,
|
|
467
|
+
} from '@/stores/demo';
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### Available Stores
|
|
471
|
+
|
|
472
|
+
| Store | Purpose |
|
|
473
|
+
|-------|---------|
|
|
474
|
+
| `$demoConnection` | Backend connection state (status, latency, errors) |
|
|
475
|
+
| `$demoGroup` | Currently selected group (id, name, type) |
|
|
476
|
+
| `$demoView` | Current view mode (list\|grid\|graph\|table) |
|
|
477
|
+
| `$demoData` | Cached API data for all resources |
|
|
478
|
+
| `$demoLoading` | Loading states per resource |
|
|
479
|
+
| `$demoErrors` | Error states per resource |
|
|
480
|
+
| `$demoUI` | UI state (sidebar, selections, expanded panels) |
|
|
481
|
+
| `$demoStats` | Statistics (totals, breakdowns) |
|
|
482
|
+
| `$demoSelection` | Multi-select state (Sets of selected IDs) |
|
|
483
|
+
|
|
484
|
+
### Store Actions
|
|
485
|
+
|
|
486
|
+
```tsx
|
|
487
|
+
// Selection
|
|
488
|
+
import { selectThing, selectConnection, selectEvent } from '@/stores/demo';
|
|
489
|
+
selectThing('thing-123');
|
|
490
|
+
|
|
491
|
+
// UI
|
|
492
|
+
import { toggleSidebar, updateDemoUI } from '@/stores/demo';
|
|
493
|
+
toggleSidebar();
|
|
494
|
+
|
|
495
|
+
updateDemoUI({
|
|
496
|
+
sidebarOpen: false,
|
|
497
|
+
selectedThingId: 'thing-123',
|
|
498
|
+
showFilters: true,
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// Data
|
|
502
|
+
import { updateDemoData, clearDemoData } from '@/stores/demo';
|
|
503
|
+
updateDemoData('things', [/* ... */]);
|
|
504
|
+
|
|
505
|
+
// Statistics
|
|
506
|
+
import { updateDemoStats } from '@/stores/demo';
|
|
507
|
+
updateDemoStats({
|
|
508
|
+
totalThings: 42,
|
|
509
|
+
thingsByType: { course: 10, blog_post: 32 },
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
// Selection (bulk operations)
|
|
513
|
+
import { toggleThingSelection, clearAllSelections } from '@/stores/demo';
|
|
514
|
+
toggleThingSelection('thing-123');
|
|
515
|
+
clearAllSelections();
|
|
516
|
+
|
|
517
|
+
// Reset all
|
|
518
|
+
import { resetAllDemoState } from '@/stores/demo';
|
|
519
|
+
resetAllDemoState();
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### Subscribe to Store Changes
|
|
523
|
+
|
|
524
|
+
```tsx
|
|
525
|
+
import { $demoConnection } from '@/stores/demo';
|
|
526
|
+
import { useAtom } from '@nanostores/react';
|
|
527
|
+
|
|
528
|
+
function Component() {
|
|
529
|
+
const [connection] = useAtom($demoConnection);
|
|
530
|
+
|
|
531
|
+
return <div>{connection.status}</div>;
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
## Integration Patterns
|
|
536
|
+
|
|
537
|
+
### Pattern 1: List with Filters
|
|
538
|
+
|
|
539
|
+
```tsx
|
|
540
|
+
import { useDemoFilters, useDemoData } from '@/hooks/demo';
|
|
541
|
+
import { Card } from '@/components/ui/card';
|
|
542
|
+
|
|
543
|
+
function ThingsList() {
|
|
544
|
+
const {
|
|
545
|
+
filters,
|
|
546
|
+
search,
|
|
547
|
+
setSearch,
|
|
548
|
+
setType,
|
|
549
|
+
debouncedSearch,
|
|
550
|
+
nextPage,
|
|
551
|
+
previousPage,
|
|
552
|
+
currentPage,
|
|
553
|
+
} = useDemoFilters();
|
|
554
|
+
|
|
555
|
+
const { data: things, loading, error } = useDemoData('things', {
|
|
556
|
+
type: filters.type,
|
|
557
|
+
search: debouncedSearch,
|
|
558
|
+
limit: filters.limit,
|
|
559
|
+
offset: filters.offset,
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
return (
|
|
563
|
+
<div className="space-y-4">
|
|
564
|
+
<div className="flex gap-2">
|
|
565
|
+
<input
|
|
566
|
+
placeholder="Search..."
|
|
567
|
+
value={search}
|
|
568
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
569
|
+
className="flex-1"
|
|
570
|
+
/>
|
|
571
|
+
<select value={filters.type || ''} onChange={(e) => setType(e.target.value || undefined)}>
|
|
572
|
+
<option value="">All Types</option>
|
|
573
|
+
<option value="course">Courses</option>
|
|
574
|
+
</select>
|
|
575
|
+
</div>
|
|
576
|
+
|
|
577
|
+
{loading ? (
|
|
578
|
+
<Skeleton count={3} />
|
|
579
|
+
) : error ? (
|
|
580
|
+
<Alert variant="destructive">{error.message}</Alert>
|
|
581
|
+
) : (
|
|
582
|
+
<div className="grid gap-4">
|
|
583
|
+
{things?.map(thing => (
|
|
584
|
+
<Card key={thing._id}>
|
|
585
|
+
<h3>{thing.name}</h3>
|
|
586
|
+
<p>{thing.properties?.description}</p>
|
|
587
|
+
</Card>
|
|
588
|
+
))}
|
|
589
|
+
</div>
|
|
590
|
+
)}
|
|
591
|
+
|
|
592
|
+
<div className="flex gap-2 justify-between">
|
|
593
|
+
<button onClick={previousPage} disabled={currentPage === 1}>
|
|
594
|
+
Previous
|
|
595
|
+
</button>
|
|
596
|
+
<span>Page {currentPage}</span>
|
|
597
|
+
<button onClick={nextPage}>Next</button>
|
|
598
|
+
</div>
|
|
599
|
+
</div>
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### Pattern 2: Create Form
|
|
605
|
+
|
|
606
|
+
```tsx
|
|
607
|
+
import { useDemoCreateMutation, useDemoData } from '@/hooks/demo';
|
|
608
|
+
import { useForm } from 'react-hook-form';
|
|
609
|
+
import { Button } from '@/components/ui/button';
|
|
610
|
+
import { Input } from '@/components/ui/input';
|
|
611
|
+
|
|
612
|
+
function CreateThingForm() {
|
|
613
|
+
const { register, handleSubmit, reset } = useForm();
|
|
614
|
+
const { refetch: refetchThings } = useDemoData('things');
|
|
615
|
+
|
|
616
|
+
const { mutate: createThing, loading, error } = useDemoCreateMutation('things', {
|
|
617
|
+
onSuccess: async () => {
|
|
618
|
+
reset();
|
|
619
|
+
await refetchThings();
|
|
620
|
+
},
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
return (
|
|
624
|
+
<form onSubmit={handleSubmit(async (data) => {
|
|
625
|
+
await createThing({
|
|
626
|
+
type: data.type,
|
|
627
|
+
name: data.name,
|
|
628
|
+
properties: { description: data.description }
|
|
629
|
+
});
|
|
630
|
+
})}>
|
|
631
|
+
<Input {...register('name')} placeholder="Name" />
|
|
632
|
+
<Input {...register('description')} placeholder="Description" />
|
|
633
|
+
<select {...register('type')}>
|
|
634
|
+
<option value="course">Course</option>
|
|
635
|
+
<option value="blog_post">Blog Post</option>
|
|
636
|
+
</select>
|
|
637
|
+
<Button disabled={loading}>{loading ? 'Creating...' : 'Create'}</Button>
|
|
638
|
+
{error && <Alert variant="destructive">{error.message}</Alert>}
|
|
639
|
+
</form>
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
### Pattern 3: Detail Page with Relations
|
|
645
|
+
|
|
646
|
+
```tsx
|
|
647
|
+
import { useDemoData } from '@/hooks/demo';
|
|
648
|
+
import { useParams } from 'react-router-dom';
|
|
649
|
+
|
|
650
|
+
function ThingDetail() {
|
|
651
|
+
const { id } = useParams();
|
|
652
|
+
const { data: things } = useDemoData('things', { /* filter to get single */ });
|
|
653
|
+
const thing = things?.[0];
|
|
654
|
+
|
|
655
|
+
const { data: connections } = useDemoData('connections', {
|
|
656
|
+
enabled: !!thing?._id,
|
|
657
|
+
// Filter to connections involving this thing
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
const { data: events } = useDemoData('events', {
|
|
661
|
+
enabled: !!thing?._id,
|
|
662
|
+
// Filter to events involving this thing
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
if (!thing) return <div>Loading...</div>;
|
|
666
|
+
|
|
667
|
+
return (
|
|
668
|
+
<div>
|
|
669
|
+
<h1>{thing.name}</h1>
|
|
670
|
+
<p>{thing.properties?.description}</p>
|
|
671
|
+
|
|
672
|
+
<section>
|
|
673
|
+
<h2>Related ({connections?.length || 0})</h2>
|
|
674
|
+
{connections?.map(conn => (
|
|
675
|
+
<div key={conn._id}>{conn.relationshipType}</div>
|
|
676
|
+
))}
|
|
677
|
+
</section>
|
|
678
|
+
|
|
679
|
+
<section>
|
|
680
|
+
<h2>Events ({events?.length || 0})</h2>
|
|
681
|
+
{events?.map(event => (
|
|
682
|
+
<div key={event._id}>{event.type}</div>
|
|
683
|
+
))}
|
|
684
|
+
</section>
|
|
685
|
+
</div>
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
## HTTP API Endpoints
|
|
691
|
+
|
|
692
|
+
Demo hooks call these endpoints:
|
|
693
|
+
|
|
694
|
+
```
|
|
695
|
+
GET /http/groups
|
|
696
|
+
GET /http/people
|
|
697
|
+
GET /http/things
|
|
698
|
+
GET /http/connections
|
|
699
|
+
GET /http/events
|
|
700
|
+
GET /http/knowledge
|
|
701
|
+
|
|
702
|
+
POST /http/{resource}
|
|
703
|
+
PATCH /http/{resource}/{id}
|
|
704
|
+
DELETE /http/{resource}/{id}
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
**Query Parameters:**
|
|
708
|
+
- `groupId` - Filter by group
|
|
709
|
+
- `type` - Filter by entity type
|
|
710
|
+
- `status` - Filter by status
|
|
711
|
+
- `search` - Full-text search
|
|
712
|
+
- `limit` - Results per page
|
|
713
|
+
- `offset` - Pagination offset
|
|
714
|
+
|
|
715
|
+
**Request Body (POST/PATCH):**
|
|
716
|
+
```json
|
|
717
|
+
{
|
|
718
|
+
"type": "course",
|
|
719
|
+
"name": "My Course",
|
|
720
|
+
"properties": {
|
|
721
|
+
"description": "...",
|
|
722
|
+
"duration": 42
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
**Response Format:**
|
|
728
|
+
```json
|
|
729
|
+
{
|
|
730
|
+
"_id": "thing_123",
|
|
731
|
+
"type": "course",
|
|
732
|
+
"name": "My Course",
|
|
733
|
+
"properties": {...},
|
|
734
|
+
"status": "draft",
|
|
735
|
+
"createdAt": 1234567890,
|
|
736
|
+
"updatedAt": 1234567890
|
|
737
|
+
}
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
## Performance Optimization
|
|
741
|
+
|
|
742
|
+
### Lazy Loading
|
|
743
|
+
|
|
744
|
+
```tsx
|
|
745
|
+
const { data } = useDemoData('things', {
|
|
746
|
+
enabled: !!groupId, // Only fetch when groupId is set
|
|
747
|
+
});
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
### Prefetching
|
|
751
|
+
|
|
752
|
+
```tsx
|
|
753
|
+
import { prefetchDemoData } from '@/hooks/demo';
|
|
754
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
755
|
+
|
|
756
|
+
const queryClient = useQueryClient();
|
|
757
|
+
|
|
758
|
+
// In effect or event handler
|
|
759
|
+
await prefetchDemoData(queryClient, 'things', { type: 'course' });
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
### Invalidation
|
|
763
|
+
|
|
764
|
+
```tsx
|
|
765
|
+
import { invalidateDemoCache } from '@/hooks/demo';
|
|
766
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
767
|
+
|
|
768
|
+
const queryClient = useQueryClient();
|
|
769
|
+
|
|
770
|
+
// After critical changes
|
|
771
|
+
invalidateDemoCache(queryClient, 'things');
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
## TypeScript Types
|
|
775
|
+
|
|
776
|
+
All hooks are fully typed:
|
|
777
|
+
|
|
778
|
+
```tsx
|
|
779
|
+
import type {
|
|
780
|
+
ConnectionStatus,
|
|
781
|
+
ResourceType,
|
|
782
|
+
ThingType,
|
|
783
|
+
ThingStatus,
|
|
784
|
+
ViewMode,
|
|
785
|
+
DemoDataOptions,
|
|
786
|
+
DemoMutationOptions,
|
|
787
|
+
DemoDataResult,
|
|
788
|
+
DemoMutationResult,
|
|
789
|
+
DemoFilters,
|
|
790
|
+
FilterState,
|
|
791
|
+
} from '@/hooks/demo';
|
|
792
|
+
|
|
793
|
+
// Usage
|
|
794
|
+
const resource: ResourceType = 'things';
|
|
795
|
+
const status: ConnectionStatus = 'connected';
|
|
796
|
+
const view: ViewMode = 'grid';
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
## Error Handling
|
|
800
|
+
|
|
801
|
+
All hooks include comprehensive error handling:
|
|
802
|
+
|
|
803
|
+
```tsx
|
|
804
|
+
const { data, error } = useDemoData('things');
|
|
805
|
+
|
|
806
|
+
if (error) {
|
|
807
|
+
console.error('Load error:', error.message);
|
|
808
|
+
if (error.message.includes('HTTP 401')) {
|
|
809
|
+
// Handle auth error
|
|
810
|
+
} else if (error.message.includes('HTTP 404')) {
|
|
811
|
+
// Handle not found
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
```
|
|
815
|
+
|
|
816
|
+
Mutations show toasts automatically:
|
|
817
|
+
|
|
818
|
+
```tsx
|
|
819
|
+
const { mutate } = useDemoCreateMutation('things');
|
|
820
|
+
// Success → green toast with message
|
|
821
|
+
// Error → red toast with error message
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
## Troubleshooting
|
|
825
|
+
|
|
826
|
+
### Data not updating after mutation
|
|
827
|
+
|
|
828
|
+
**Problem:** Mutation succeeds but UI doesn't update
|
|
829
|
+
|
|
830
|
+
**Solution:** Mutation hooks automatically invalidate related queries. If data still doesn't update:
|
|
831
|
+
|
|
832
|
+
```tsx
|
|
833
|
+
const { mutate, data } = useDemoCreateMutation('things');
|
|
834
|
+
|
|
835
|
+
const { refetch } = useDemoData('things'); // Get refetch function
|
|
836
|
+
|
|
837
|
+
await mutate(data);
|
|
838
|
+
await refetch(); // Manual refetch if needed
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
### Filters not syncing to URL
|
|
842
|
+
|
|
843
|
+
**Problem:** URL doesn't update when filters change
|
|
844
|
+
|
|
845
|
+
**Solution:** Ensure you're using `useDemoFilters` in a routed component:
|
|
846
|
+
|
|
847
|
+
```tsx
|
|
848
|
+
// Correct - in route component
|
|
849
|
+
function ThingsPage() {
|
|
850
|
+
const filters = useDemoFilters(); // Gets URL from window.location
|
|
851
|
+
// ...
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// Wrong - in nested component without context
|
|
855
|
+
function ThingsList() {
|
|
856
|
+
const filters = useDemoFilters(); // No URL access in fragment
|
|
857
|
+
}
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
### Connection keeps failing
|
|
861
|
+
|
|
862
|
+
**Problem:** Backend connection shows 'disconnected' or 'error'
|
|
863
|
+
|
|
864
|
+
**Solution:**
|
|
865
|
+
1. Check backend URL: `https://veracious-marlin-319.convex.cloud`
|
|
866
|
+
2. Verify network connectivity
|
|
867
|
+
3. Check CORS headers
|
|
868
|
+
4. Monitor console for failed health checks
|
|
869
|
+
|
|
870
|
+
```tsx
|
|
871
|
+
import { checkBackendHealth } from '@/hooks/demo';
|
|
872
|
+
|
|
873
|
+
const latency = await checkBackendHealth();
|
|
874
|
+
console.log('Latency:', latency);
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
### Search not working
|
|
878
|
+
|
|
879
|
+
**Problem:** Search filters don't apply
|
|
880
|
+
|
|
881
|
+
**Solution:** Use `debouncedSearch`, not `search`:
|
|
882
|
+
|
|
883
|
+
```tsx
|
|
884
|
+
// Correct
|
|
885
|
+
const { data } = useDemoData('things', { search: debouncedSearch });
|
|
886
|
+
|
|
887
|
+
// Wrong - triggers on every keystroke
|
|
888
|
+
const { data } = useDemoData('things', { search });
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
## Next Steps
|
|
892
|
+
|
|
893
|
+
1. **Integrate into demo pages** - Use hooks in `/web/src/pages/demo/*.astro`
|
|
894
|
+
2. **Add connection status UI** - Show backend health in header
|
|
895
|
+
3. **Implement filters** - Add search, type, status filtering to all lists
|
|
896
|
+
4. **Create forms** - Use mutation hooks for create/update/delete
|
|
897
|
+
5. **Add pagination** - Implement next/previous pagination
|
|
898
|
+
6. **Share filters** - Share filter URLs with stakeholders
|
|
899
|
+
|
|
900
|
+
## Related Documentation
|
|
901
|
+
|
|
902
|
+
- `/web/src/hooks/demo/README.md` - Complete hook documentation
|
|
903
|
+
- `/web/src/stores/demo.ts` - Store definitions and actions
|
|
904
|
+
- `/web/CLAUDE.md` - Development patterns and guidelines
|
|
905
|
+
- `/one/knowledge/ontology.md` - 6-dimension data model
|