diff --git a/src/styles/GlobalStyle.ts b/src/styles/GlobalStyle.ts
index 5b9468a..2b972d4 100644
--- a/src/styles/GlobalStyle.ts
+++ b/src/styles/GlobalStyle.ts
@@ -284,6 +284,7 @@ export default createGlobalStyle`
}
.dynamic-group{
padding-top: 1rem;
+ padding-bottom: 0rem;
}
.grid-checkbox-group.large-label {
grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
From 0115a81d14fb8c7182fa954d9de89a5e3ff0b65c Mon Sep 17 00:00:00 2001
From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com>
Date: Wed, 31 Jul 2024 16:57:33 -0700
Subject: [PATCH 04/15] removed unnecessary cache
---
src/hooks/useRelaySettings.ts | 5 +++--
src/pages/RelaySettingsPage.tsx | 8 +++-----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/hooks/useRelaySettings.ts b/src/hooks/useRelaySettings.ts
index fb2215b..fafe845 100644
--- a/src/hooks/useRelaySettings.ts
+++ b/src/hooks/useRelaySettings.ts
@@ -14,6 +14,7 @@ interface RelaySettings {
videos: string[];
gitNestr: string[];
audio: string[];
+ appBuckets: string[];
isKindsActive: boolean;
isPhotosActive: boolean;
isVideosActive: boolean;
@@ -22,7 +23,7 @@ interface RelaySettings {
}
const getInitialSettings = (): RelaySettings => {
- const savedSettings = localStorage.getItem('settingsCache');
+ const savedSettings = localStorage.getItem('relaySettings');
return savedSettings
? JSON.parse(savedSettings)
: {
@@ -38,6 +39,7 @@ const getInitialSettings = (): RelaySettings => {
videos: [],
gitNestr: [],
audio: [],
+ appBuckets: [],
isKindsActive: true,
isPhotosActive: true,
isVideosActive: true,
@@ -75,7 +77,6 @@ const useRelaySettings = () => {
? data.relay_settings.chunked
: [data.relay_settings.chunked],
});
- localStorage.setItem('settingsCache', JSON.stringify(data.relay_settings));
localStorage.setItem('relaySettings', JSON.stringify(data.relay_settings));
} catch (error) {
console.error('Error fetching settings:', error);
diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx
index 360f232..a5bc871 100644
--- a/src/pages/RelaySettingsPage.tsx
+++ b/src/pages/RelaySettingsPage.tsx
@@ -35,6 +35,7 @@ type Settings = {
videos: string[];
gitNestr: string[];
audio: string[];
+ appBuckets: string[];
isKindsActive: boolean;
isPhotosActive: boolean;
isVideosActive: boolean;
@@ -126,6 +127,7 @@ const RelaySettingsPage: React.FC = () => {
videos: [],
gitNestr: [],
audio: [],
+ appBuckets: [],
isKindsActive: true,
isPhotosActive: true,
isVideosActive: true,
@@ -423,6 +425,7 @@ const RelaySettingsPage: React.FC = () => {
...relaySettings,
protocol: Array.isArray(relaySettings.protocol) ? relaySettings.protocol : [relaySettings.protocol],
chunked: Array.isArray(relaySettings.chunked) ? relaySettings.chunked : [relaySettings.chunked],
+ appBuckets: [],
});
}
}, [relaySettings]);
@@ -449,11 +452,6 @@ const RelaySettingsPage: React.FC = () => {
const [newKind, setNewKind] = useState('');
- useEffect(() => {
- return () => {
- localStorage.setItem('relaySettings', localStorage.getItem('settingsCache') || '{}');
- };
- }, []);
const removeDynamicKind = (kind: string) => {
setSettings((prevSettings) => ({
...prevSettings,
From 1e7b68e4da9e085d9cbb445ac426d8e1a360d0ed Mon Sep 17 00:00:00 2001
From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com>
Date: Fri, 2 Aug 2024 12:41:45 -0700
Subject: [PATCH 05/15] feat: app storage of dynamic kind/app buckets
---
src/constants/relaySettings.ts | 64 +++++
src/hooks/useRelaySettings.ts | 17 +-
src/pages/RelaySettingsPage.tsx | 462 ++++++++++++++------------------
3 files changed, 280 insertions(+), 263 deletions(-)
create mode 100644 src/constants/relaySettings.ts
diff --git a/src/constants/relaySettings.ts b/src/constants/relaySettings.ts
new file mode 100644
index 0000000..ad1ba58
--- /dev/null
+++ b/src/constants/relaySettings.ts
@@ -0,0 +1,64 @@
+export type Settings = {
+ mode: string;
+ protocol: string[];
+ chunked: string[];
+ chunksize: string;
+ maxFileSize: number;
+ maxFileSizeUnit: string;
+ kinds: string[];
+ dynamicKinds: string[];
+ photos: string[];
+ videos: string[];
+ gitNestr: string[];
+ audio: string[];
+ appBuckets: string[];
+ dynamicAppBuckets: string[];
+ isKindsActive: boolean;
+ isPhotosActive: boolean;
+ isVideosActive: boolean;
+ isGitNestrActive: boolean;
+ isAudioActive: boolean;
+};
+
+export type Category = 'kinds' | 'photos' | 'videos' | 'gitNestr' | 'audio' | 'dynamicKinds' | 'appBuckets' | 'dynamicAppBuckets';
+export const noteOptions = [
+ { kind: 0, kindString: 'kind0', description: 'Metadata', category: 1 },
+ { kind: 1, kindString: 'kind1', description: 'Text Note', category: 1 },
+ { kind: 2, kindString: 'kind2', description: 'Recommend Relay', category: 1 },
+ { kind: 3, kindString: 'kind3', description: 'Follow List', category: 1 },
+ { kind: 5, kindString: 'kind5', description: 'Event Deletion', category: 1 },
+ { kind: 6, kindString: 'kind6', description: 'Repost', category: 1 },
+ { kind: 7, kindString: 'kind7', description: 'Reaction', category: 1 },
+ { kind: 8, kindString: 'kind8', description: 'Badge Award', category: 2 },
+ { kind: 16, kindString: 'kind16', description: 'Generic Repost', category: 1 },
+ { kind: 10000, kindString: 'kind10000', description: 'Mute List', category: 1 },
+ { kind: 10001, kindString: 'kind10001', description: 'Pinned Note(s)', category: 1 },
+ { kind: 10002, kindString: 'kind10002', description: 'Tiny Relay List', category: 1 },
+ { kind: 1984, kindString: 'kind1984', description: 'Reporting', category: 1 },
+ { kind: 30000, kindString: 'kind30000', description: 'Custom Follow List', category: 1 },
+ { kind: 30008, kindString: 'kind30008', description: 'Profile Badge', category: 2 },
+ { kind: 30009, kindString: 'kind30009', description: 'Badge Definition', category: 2 },
+ { kind: 30023, kindString: 'kind30023', description: 'Formatted Articles', category: 1 },
+ { kind: 30079, kindString: 'kind30079', description: 'Event Paths', category: 1 },
+ //{ kind: 9734, kindString: 'kind9734', description: 'Lightning Zap Request', category: 2 },
+ { kind: 9735, kindString: 'kind9735', description: 'Zap Receipt', category: 2 },
+ { kind: 10011, kindString: 'kind10011', description: 'Issue Notes', category: 3 },
+ { kind: 10022, kindString: 'kind10022', description: 'PR Notes', category: 3 },
+ { kind: 9803, kindString: 'kind9803', description: 'Commit Notes', category: 3 },
+];
+export const appBuckets = [
+ { id: 'nostr', label: 'Nostr' },
+ {
+ id: 'gitnestr',
+ label: 'GitNestr',
+ },
+ {
+ id: 'NostrBox',
+ label: 'NostrBox',
+ },
+];
+export const categories = [
+ { id: 1, name: 'Basic Nostr Features' },
+ { id: 2, name: 'Extra Nostr Features' },
+ { id: 3, name: 'GitNestr Features' },
+];
diff --git a/src/hooks/useRelaySettings.ts b/src/hooks/useRelaySettings.ts
index fafe845..5583b9a 100644
--- a/src/hooks/useRelaySettings.ts
+++ b/src/hooks/useRelaySettings.ts
@@ -15,6 +15,7 @@ interface RelaySettings {
gitNestr: string[];
audio: string[];
appBuckets: string[];
+ dynamicAppBuckets: string[];
isKindsActive: boolean;
isPhotosActive: boolean;
isVideosActive: boolean;
@@ -40,6 +41,7 @@ const getInitialSettings = (): RelaySettings => {
gitNestr: [],
audio: [],
appBuckets: [],
+ dynamicAppBuckets: [],
isKindsActive: true,
isPhotosActive: true,
isVideosActive: true,
@@ -66,8 +68,21 @@ const useRelaySettings = () => {
if (!response.ok) {
throw new Error(`Network response was not ok (status: ${response.status})`);
}
+
const data = await response.json();
- console.log('Fetched settings:', data.relay_settings);
+
+ const storedAppBuckets = JSON.parse(localStorage.getItem('appBuckets') || '[]');
+ const storedDynamicKinds = JSON.parse(localStorage.getItem('dynamicKinds') || '[]');
+
+ const newAppBuckets = data.dynamicAppBuckets.filter((bucket: string) => !storedAppBuckets.includes(bucket));
+ const newDynamicKinds = data.dynamicKinds.filter((kind :string) => !storedDynamicKinds.includes(kind));
+
+ if (newAppBuckets.length > 0) {
+ localStorage.setItem('appBuckets', JSON.stringify([...storedAppBuckets, ...newAppBuckets]));
+ }
+ if (newDynamicKinds.length > 0) {
+ localStorage.setItem('dynamicKinds', JSON.stringify([...storedDynamicKinds, ...newDynamicKinds]));
+ }
setRelaySettings({
...data.relay_settings,
protocol: Array.isArray(data.relay_settings.protocol)
diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx
index a5bc871..4cce9e7 100644
--- a/src/pages/RelaySettingsPage.tsx
+++ b/src/pages/RelaySettingsPage.tsx
@@ -17,34 +17,11 @@ import { useResponsive } from '@app/hooks/useResponsive';
import useRelaySettings from '@app/hooks/useRelaySettings';
import * as S from '@app/pages/uiComponentsPages/UIComponentsPage.styles';
import { themeObject } from '@app/styles/themes/themeVariables';
-
+import { categories, noteOptions, appBuckets, Settings, Category } from '@app/constants/relaySettings';
const { Panel } = Collapse;
const StyledPanel = styled(Panel)``;
const { Option } = Select;
-type Settings = {
- mode: string;
- protocol: string[];
- chunked: string[];
- chunksize: string;
- maxFileSize: number;
- maxFileSizeUnit: string;
- kinds: string[];
- dynamicKinds: string[];
- photos: string[];
- videos: string[];
- gitNestr: string[];
- audio: string[];
- appBuckets: string[];
- isKindsActive: boolean;
- isPhotosActive: boolean;
- isVideosActive: boolean;
- isGitNestrActive: boolean;
- isAudioActive: boolean;
-};
-
-type RelaySettings = Settings; // Ensure RelaySettings matches the structure of Settings
-
const RelaySettingsPage: React.FC = () => {
const theme = useAppSelector((state) => state.theme.theme);
const [loadings, setLoadings] = useState
([]);
@@ -70,49 +47,12 @@ const RelaySettingsPage: React.FC = () => {
const relaymode = useAppSelector((state) => state.mode.relayMode);
const { isDesktop } = useResponsive();
- const categories = [
- { id: 1, name: 'Basic Nostr Features' },
- { id: 2, name: 'Extra Nostr Features' },
- { id: 3, name: 'GitNestr Features' },
- ];
-
- const appBuckets = [
- { id: 'nostr', label: 'Nostr' },
- {
- id: 'gitnestr',
- label: 'GitNestr',
- },
- {
- id: 'NostrBox',
- label: 'NostrBox',
- },
- ];
-
- const noteOptions = [
- { kind: 0, kindString: 'kind0', description: 'Metadata', category: 1 },
- { kind: 1, kindString: 'kind1', description: 'Text Note', category: 1 },
- { kind: 2, kindString: 'kind2', description: 'Recommend Relay', category: 1 },
- { kind: 3, kindString: 'kind3', description: 'Follow List', category: 1 },
- { kind: 5, kindString: 'kind5', description: 'Event Deletion', category: 1 },
- { kind: 6, kindString: 'kind6', description: 'Repost', category: 1 },
- { kind: 7, kindString: 'kind7', description: 'Reaction', category: 1 },
- { kind: 8, kindString: 'kind8', description: 'Badge Award', category: 2 },
- { kind: 16, kindString: 'kind16', description: 'Generic Repost', category: 1 },
- { kind: 10000, kindString: 'kind10000', description: 'Mute List', category: 1 },
- { kind: 10001, kindString: 'kind10001', description: 'Pinned Note(s)', category: 1 },
- { kind: 10002, kindString: 'kind10002', description: 'Tiny Relay List', category: 1 },
- { kind: 1984, kindString: 'kind1984', description: 'Reporting', category: 1 },
- { kind: 30000, kindString: 'kind30000', description: 'Custom Follow List', category: 1 },
- { kind: 30008, kindString: 'kind30008', description: 'Profile Badge', category: 2 },
- { kind: 30009, kindString: 'kind30009', description: 'Badge Definition', category: 2 },
- { kind: 30023, kindString: 'kind30023', description: 'Formatted Articles', category: 1 },
- { kind: 30079, kindString: 'kind30079', description: 'Event Paths', category: 1 },
- //{ kind: 9734, kindString: 'kind9734', description: 'Lightning Zap Request', category: 2 },
- { kind: 9735, kindString: 'kind9735', description: 'Zap Receipt', category: 2 },
- { kind: 10011, kindString: 'kind10011', description: 'Issue Notes', category: 3 },
- { kind: 10022, kindString: 'kind10022', description: 'PR Notes', category: 3 },
- { kind: 9803, kindString: 'kind9803', description: 'Commit Notes', category: 3 },
- ];
+ const [storedDynamicKinds, setStoredDynamicKinds] = useState(
+ JSON.parse(localStorage.getItem('dynamicKinds') || '[]'),
+ );
+ const [storedAppBuckets, setStoredAppBuckets] = useState(
+ JSON.parse(localStorage.getItem('appBuckets') || '[]'),
+ );
const [settings, setSettings] = useState({
mode: JSON.parse(localStorage.getItem('relaySettings') || '{}').mode || relaymode || 'unlimited',
@@ -128,15 +68,13 @@ const RelaySettingsPage: React.FC = () => {
gitNestr: [],
audio: [],
appBuckets: [],
+ dynamicAppBuckets: [],
isKindsActive: true,
isPhotosActive: true,
isVideosActive: true,
isGitNestrActive: true,
isAudioActive: true,
});
-
- type Category = 'kinds' | 'photos' | 'videos' | 'gitNestr' | 'audio' | 'dynamicKinds';
-
const groupedNoteOptions = categories.map((category) => ({
...category,
notes: noteOptions.filter((note) => note.category === category.id),
@@ -274,6 +212,8 @@ const RelaySettingsPage: React.FC = () => {
const chunkSizeOptions = ['2', '4', '6', '8', '10', '12'];
const maxFileSizeUnitOptions = ['MB', 'GB', 'TB'];
+ const [newKind, setNewKind] = useState('');
+ const [newBucket, setNewBucket] = useState('');
const [blacklist, setBlacklist] = useState({
kinds: [],
photos: [],
@@ -307,7 +247,7 @@ const RelaySettingsPage: React.FC = () => {
};
const handleBlacklistChange = (category: Category, checkedValues: string[]) => {
- const isDynamicKind = category === 'dynamicKinds';
+ const isDynamicKind = category === 'dynamicKinds' || 'appBuckets';
if (isDynamicKind) {
setSettings((prevSettings) => {
const updatedSettings = { ...prevSettings, [category]: checkedValues };
@@ -374,6 +314,38 @@ const RelaySettingsPage: React.FC = () => {
updateSettings('maxFileSizeUnit', value);
};
+ const handleNewBucket = (bucket: string) => {
+ const currentBuckets = settings.appBuckets.concat(storedAppBuckets);
+ if (currentBuckets.includes(bucket)) {
+ return;
+ }
+ setStoredAppBuckets((prevBuckets) => [...prevBuckets, bucket]);
+ handleSettingsChange('appBuckets', [...settings.appBuckets, bucket]);
+ };
+ const handleRemovedBucket = (bucket: string) => {
+ setStoredAppBuckets((prevBuckets) => prevBuckets.filter((b) => b !== bucket));
+ handleSettingsChange(
+ 'appBuckets',
+ settings.appBuckets.filter((b) => b !== bucket),
+ );
+ };
+
+ const handleNewDynamicKind = (kind: string) => {
+ const currentKinds = settings.dynamicKinds.concat(storedDynamicKinds);
+ if (currentKinds.includes(kind)) {
+ return;
+ }
+ setStoredDynamicKinds((prevKinds) => [...prevKinds, kind]);
+ handleSettingsChange('dynamicKinds', [...settings.dynamicKinds, kind]);
+ };
+ const removeDynamicKind = (kind: string) => {
+ setStoredDynamicKinds((prevKinds) => prevKinds.filter((k) => k !== kind));
+ handleSettingsChange(
+ 'dynamicKinds',
+ settings.dynamicKinds.filter((k) => k !== kind),
+ );
+ };
+
const performSaveSettings = async () => {
await Promise.all([
updateSettings('kinds', settings.isKindsActive ? settings.kinds : []),
@@ -386,7 +358,8 @@ const RelaySettingsPage: React.FC = () => {
updateSettings('chunked', settings.chunked),
updateSettings('maxFileSize', settings.maxFileSize),
updateSettings('maxFileSizeUnit', settings.maxFileSizeUnit),
- //TODO: update blacklist
+ updateSettings('appBuckets', settings.appBuckets),
+ updateSettings('dynamicAppBuckets', settings.dynamicAppBuckets),
]);
await saveSettings();
@@ -425,7 +398,6 @@ const RelaySettingsPage: React.FC = () => {
...relaySettings,
protocol: Array.isArray(relaySettings.protocol) ? relaySettings.protocol : [relaySettings.protocol],
chunked: Array.isArray(relaySettings.chunked) ? relaySettings.chunked : [relaySettings.chunked],
- appBuckets: [],
});
}
}, [relaySettings]);
@@ -440,6 +412,13 @@ const RelaySettingsPage: React.FC = () => {
});
}, [settings.mode]);
+ useEffect(() => {
+ localStorage.setItem('appBuckets', JSON.stringify(storedAppBuckets));
+ }, [storedAppBuckets]);
+ useEffect(() => {
+ localStorage.setItem('dynamicKinds', JSON.stringify(storedDynamicKinds));
+ }, [storedDynamicKinds]);
+
useEffect(() => {
const updateDynamicKinds = async () => {
await performSaveSettings();
@@ -449,16 +428,7 @@ const RelaySettingsPage: React.FC = () => {
updateDynamicKinds();
}
}, [settings.dynamicKinds]);
-
- const [newKind, setNewKind] = useState('');
-
- const removeDynamicKind = (kind: string) => {
- setSettings((prevSettings) => ({
- ...prevSettings,
- dynamicKinds: prevSettings.dynamicKinds.filter((k) => k !== kind),
- }));
- };
-
+
const desktopLayout = (
@@ -568,96 +538,86 @@ const RelaySettingsPage: React.FC = () => {
- {settings.mode !== 'unlimited' && settings.mode !== '' && (
-
- {}} //TODO handle change
- />
-
- )}
+
+ {}} //TODO handle change
+ />
+
handleSettingsChange('kinds', checkedValues as string[])}
- disabled={settings.mode !== 'smart' ? false : !settings.isKindsActive}
+ style={{ paddingTop: '1rem', paddingLeft: '1rem' }}
+ className={`custom-checkbox-group grid-checkbox-group`}
+ onChange={(checkedValues) => handleSettingsChange('appBuckets', checkedValues as string[])}
options={appBucketOptions}
/>
- {settings.mode !== 'smart' && (
+
+
{'Add an App Bucket'}
-
{'Add an App Bucket'}
-
{
+ setNewBucket(e.target.value);
+ }}
+ placeholder="Enter new app bucket"
+ />
+ {
+ if (newBucket) {
+ handleNewBucket(newBucket);
+ setNewBucket('');
+ }
+ }}
>
- {}} //TODO: handle changes
- placeholder="Enter new app bucket"
- />
- {
- if (newKind) {
- setSettings((prevSettings) => ({
- ...prevSettings,
- dynamicKinds: [...(prevSettings.dynamicKinds || []), newKind],
- }));
- setNewKind('');
- }
- }}
+ Add bucket
+
+
+
+ handleSettingsChange('dynamicAppBuckets', checkedValues as string[])
+ }
+ >
+ {(storedAppBuckets || []).map((bucket) => (
+
- Add bucket
-
-
- handleSettingsChange('dynamicKinds', checkedValues as string[])}
- >
- {(settings.dynamicKinds || []).map((kind) => (
-
-
-
-
- {`kind` + kind}
-
-
-
removeDynamicKind(kind)}
+
+
+
- Remove
-
+ {bucket}
+
- ))}
-
-
- )}
+ handleRemovedBucket(bucket)}
+ >
+ Remove
+
+
+ ))}
+
+
@@ -704,7 +664,6 @@ const RelaySettingsPage: React.FC = () => {