docs udpated
This commit is contained in:
@@ -883,6 +883,93 @@ const handleSchedule = async () => {
|
||||
|
||||
## 5. Integration Patterns
|
||||
|
||||
### Site Selector Integration
|
||||
|
||||
**Critical Pattern**: All pages must reload data when `activeSite` changes.
|
||||
|
||||
**Correct Implementation** (from ContentCalendar.tsx):
|
||||
```typescript
|
||||
const loadQueue = useCallback(async () => {
|
||||
if (!activeSite?.id) {
|
||||
console.log('[ContentCalendar] No active site selected, skipping load');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// All API calls MUST include site_id parameter
|
||||
const scheduledResponse = await fetchAPI('/v1/writer/content/', {
|
||||
params: {
|
||||
site_id: activeSite.id, // ← REQUIRED
|
||||
page_size: 1000,
|
||||
site_status: 'scheduled',
|
||||
}
|
||||
});
|
||||
|
||||
// ... more queries
|
||||
setAllContent(uniqueItems);
|
||||
} catch (error: any) {
|
||||
toast.error(`Failed to load content: ${error.message}`);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [activeSite?.id, toast]);
|
||||
|
||||
// ✅ CORRECT: Only depend on activeSite?.id
|
||||
useEffect(() => {
|
||||
if (activeSite?.id) {
|
||||
console.log('[ContentCalendar] Site changed to:', activeSite.id, activeSite.name);
|
||||
loadQueue();
|
||||
} else {
|
||||
console.log('[ContentCalendar] No active site, clearing content');
|
||||
setAllContent([]);
|
||||
}
|
||||
}, [activeSite?.id]); // Do NOT include loadQueue here
|
||||
```
|
||||
|
||||
**Common Mistakes**:
|
||||
```typescript
|
||||
// ❌ WRONG: Circular dependency
|
||||
useEffect(() => {
|
||||
if (activeSite?.id) {
|
||||
loadQueue();
|
||||
}
|
||||
}, [activeSite?.id, loadQueue]); // loadQueue changes on every render
|
||||
|
||||
// ❌ WRONG: Missing site_id in API call
|
||||
const response = await fetchAPI('/v1/writer/content/', {
|
||||
params: {
|
||||
site_status: 'scheduled', // Missing site_id!
|
||||
}
|
||||
});
|
||||
|
||||
// ❌ WRONG: Not clearing data when site is null
|
||||
useEffect(() => {
|
||||
if (activeSite?.id) {
|
||||
loadQueue();
|
||||
}
|
||||
// Should clear data here if activeSite is null
|
||||
}, [activeSite?.id]);
|
||||
```
|
||||
|
||||
**Backend Requirements**:
|
||||
The backend ContentFilter must include `site_id` in filterable fields:
|
||||
```python
|
||||
# backend/igny8_core/modules/writer/views.py
|
||||
class ContentFilter(django_filters.FilterSet):
|
||||
class Meta:
|
||||
model = Content
|
||||
fields = [
|
||||
'cluster_id',
|
||||
'site_id', # ← REQUIRED for site filtering
|
||||
'status',
|
||||
'site_status', # ← REQUIRED for status filtering
|
||||
'content_type',
|
||||
# ...
|
||||
]
|
||||
```
|
||||
|
||||
### Parent Component Setup (Approved.tsx)
|
||||
|
||||
```typescript
|
||||
|
||||
Reference in New Issue
Block a user