Skip to content

Commit f4d1ead

Browse files
committed
Fix dynamic kinds handling in blacklist mode
- Properly include dynamic kinds in backend whitelist calculation - Separate predefined vs dynamic kinds in reconciliation logic - Fix kind formatting in AddKindForm - Improve UI labels for better UX - Show dynamic kinds in both whitelist and blacklist modes
1 parent 83277c1 commit f4d1ead

3 files changed

Lines changed: 39 additions & 17 deletions

File tree

src/components/relay-settings/sections/KindsSection/components/AddKindForm.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,21 @@ export const AddKindForm: React.FC<AddKindFormProps> = ({ onAddKind, mode }) =>
1414

1515
const handleAddKind = () => {
1616
if (newKind) {
17-
onAddKind(newKind);
17+
// Ensure the kind is in the correct format
18+
const formattedKind = newKind.startsWith('kind') ? newKind : `kind${newKind}`;
19+
onAddKind(formattedKind);
1820
setNewKind('');
1921
}
2022
};
2123

22-
if (mode === 'whitelist') {
23-
return null;
24-
}
25-
2624
return (
2725
<div style={{ padding: '1.5rem 0rem 0rem 0rem', display: 'flex', flexDirection: 'column', gap: '.5rem' }}>
28-
<h3>{'Add to Blacklist'}</h3>
26+
<h3>{mode === 'blacklist' ? 'Add Custom Kind to Whitelist' : 'Add Custom Kind'}</h3>
2927
<div style={{ display: 'flex' }} className="custom-checkbox-group grid-checkbox-group large-label">
3028
<Input
3129
value={newKind}
3230
onChange={(e) => setNewKind(e.target.value)}
33-
placeholder="Enter new kind"
31+
placeholder="Enter kind number (e.g., 12345)"
3432
/>
3533
<BaseButton onClick={handleAddKind}>
3634
Add Kind

src/components/relay-settings/sections/KindsSection/components/DynamicKindsList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const DynamicKindsList: React.FC<DynamicKindsListProps> = ({
2121
onRemoveKind,
2222
mode,
2323
}) => {
24-
if (!dynamicKinds.length || mode === 'whitelist') {
24+
if (!dynamicKinds.length) {
2525
return null;
2626
}
2727

@@ -50,7 +50,7 @@ export const DynamicKindsList: React.FC<DynamicKindsListProps> = ({
5050
isActive={true}
5151
style={{ fontSize: '1rem', paddingRight: '.8rem', paddingLeft: '.8rem' }}
5252
>
53-
{`kind` + kind}
53+
{kind}
5454
</S.CheckboxLabel>
5555
</div>
5656
<BaseButton

src/hooks/useRelaySettings.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,35 @@ const useRelaySettings = () => {
116116
// Handle kinds based on mode
117117
const backendKinds = backendData.event_filtering.kind_whitelist || [];
118118

119+
// Get all stored dynamic kinds from localStorage
120+
const allStoredDynamicKinds = JSON.parse(localStorage.getItem('dynamicKinds') || '[]');
121+
119122
if (settings.mode === 'blacklist') {
120123
// In blacklist mode: backend sends allowed kinds, we need to calculate blocked kinds
121124
const allPossibleKinds = getAllPossibleKinds();
122125
const backendKindsSet = new Set(backendKinds);
123126
const allKindsSet = new Set(allPossibleKinds);
124127

125-
// Calculate blocked kinds: all possible kinds minus backend allowed kinds
126-
const blockedKinds = Array.from(allKindsSet).filter(kind => !backendKindsSet.has(kind));
128+
// Calculate blocked predefined kinds: all possible kinds minus backend allowed kinds
129+
const blockedPredefinedKinds = Array.from(allKindsSet).filter(kind => !backendKindsSet.has(kind));
127130
// Only show non-core kinds as blocked (core kinds can't be blocked)
128-
settings.kinds = blockedKinds.filter(kind => !isCoreKind(kind));
131+
settings.kinds = blockedPredefinedKinds.filter(kind => !isCoreKind(kind));
132+
133+
// Calculate blocked dynamic kinds: stored dynamic kinds that are NOT in backend allowed kinds
134+
settings.dynamicKinds = allStoredDynamicKinds.filter((kind: string) => !backendKindsSet.has(kind));
129135

130136
console.log('[useRelaySettings] Blacklist mode - Backend allowed kinds:', backendKinds);
131-
console.log('[useRelaySettings] Blacklist mode - Calculated blocked kinds:', settings.kinds);
137+
console.log('[useRelaySettings] Blacklist mode - Calculated blocked predefined kinds:', settings.kinds);
138+
console.log('[useRelaySettings] Blacklist mode - Calculated blocked dynamic kinds:', settings.dynamicKinds);
132139
} else {
133140
// In whitelist mode: backend sends allowed kinds directly
134-
settings.kinds = ensureCoreKinds(backendKinds);
141+
// Separate predefined kinds from dynamic kinds
142+
const allPossibleKinds = getAllPossibleKinds();
143+
const predefinedKinds = backendKinds.filter((kind: string) => allPossibleKinds.includes(kind));
144+
const dynamicKinds = backendKinds.filter((kind: string) => !allPossibleKinds.includes(kind) && allStoredDynamicKinds.includes(kind));
145+
146+
settings.kinds = ensureCoreKinds(predefinedKinds);
147+
settings.dynamicKinds = dynamicKinds;
135148
}
136149

137150
// Extract mime types and file sizes from actual backend format
@@ -242,9 +255,20 @@ const useRelaySettings = () => {
242255
event_filtering: {
243256
mode: settings.mode,
244257
moderation_mode: settings.moderationMode,
245-
kind_whitelist: settings.mode === 'blacklist'
246-
? calculateInverseKinds(settings.kinds) // For blacklist: send inverse (all kinds except blocked ones)
247-
: ensureCoreKinds(settings.kinds), // For whitelist: send selected kinds directly
258+
kind_whitelist: (() => {
259+
if (settings.mode === 'blacklist') {
260+
// For blacklist: get all predefined allowed kinds, then add unblocked dynamic kinds
261+
const predefinedAllowed = calculateInverseKinds(settings.kinds);
262+
// Get all stored dynamic kinds from localStorage
263+
const allStoredDynamicKinds = JSON.parse(localStorage.getItem('dynamicKinds') || '[]');
264+
// Add dynamic kinds that are NOT blocked (not in settings.dynamicKinds)
265+
const allowedDynamicKinds = allStoredDynamicKinds.filter((kind: string) => !settings.dynamicKinds.includes(kind));
266+
return [...predefinedAllowed, ...allowedDynamicKinds];
267+
} else {
268+
// For whitelist: send all selected kinds (including dynamic)
269+
return ensureCoreKinds([...settings.kinds, ...settings.dynamicKinds]);
270+
}
271+
})(),
248272
media_definitions: mediaDefinitions,
249273
dynamic_kinds: {
250274
enabled: false,

0 commit comments

Comments
 (0)