From 91476871b01284a55c2ed62a3d2cfb79e9289ce5 Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:00:28 -0700 Subject: [PATCH 01/15] basic layout --- src/pages/RelaySettingsPage.tsx | 349 +++++++++++++++--- .../UIComponentsPage.styles.ts | 4 + 2 files changed, 305 insertions(+), 48 deletions(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index 3075fc9..279e4e1 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -17,6 +17,7 @@ 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'; + const { Panel } = Collapse; const StyledPanel = styled(Panel)``; const { Option } = Select; @@ -74,6 +75,18 @@ const RelaySettingsPage: React.FC = () => { { 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 }, @@ -179,6 +192,25 @@ const RelaySettingsPage: React.FC = () => { value: format, })); + const appBucketOptions = appBuckets.map((bucket) => ({ + label: ( + + {bucket.label} + + ), + value: bucket.id, + })); + const audioFormatOptions = [ 'mp3', 'wav', @@ -434,25 +466,9 @@ const RelaySettingsPage: React.FC = () => { - - {t('common.serverSetting')} - handleModeChange(e)} - /> - + {'Options'} - +
@@ -548,10 +564,130 @@ const RelaySettingsPage: React.FC = () => { + + + +
+ {settings.mode !== 'unlimited' && settings.mode !== '' && ( +
+ {}} //TODO handle change + /> +
+ )} + handleSettingsChange('kinds', checkedValues as string[])} + disabled={settings.mode !== 'smart' ? false : !settings.isKindsActive} + options={appBucketOptions} + /> + + {settings.mode !== 'smart' && ( +
+

{'Add an App Bucket'}

+
+ {}} //TODO: handle changes + placeholder="Enter new app bucket" + /> + { + if (newKind) { + setSettings((prevSettings) => ({ + ...prevSettings, + dynamicKinds: [...(prevSettings.dynamicKinds || []), newKind], + })); + setNewKind(''); + } + }} + > + Add bucket + +
+ handleSettingsChange('dynamicKinds', checkedValues as string[])} + > + {(settings.dynamicKinds || []).map((kind) => ( +
+
+ + + {`kind` + kind} + +
+ removeDynamicKind(kind)} + > + Remove + +
+ ))} +
+
+ )} +
+
+
+
+ + {t('common.serverSetting')} + handleModeChange(e)} + /> + {

{group.name}

{group.notes.map((note) => ( -
+
{ {settings.mode !== 'smart' && (

{'Add to Blacklist'}

{ onClick={() => { if (newKind) { setSettings((prevSettings) => ({ + /// TODO: don't allow duplicates ...prevSettings, dynamicKinds: [...(prevSettings.dynamicKinds || []), newKind], })); @@ -652,7 +794,7 @@ const RelaySettingsPage: React.FC = () => { style={{ display: 'flex', flexDirection: 'row', gap: '.5rem', alignItems: 'center' }} key={kind} > -
+
{ isActive={true} style={{ fontSize: '1rem', paddingRight: '.8rem', paddingLeft: '.8rem' }} > - {`kind`+kind} + {`kind` + kind}
removeDynamicKind(kind)} > Remove @@ -771,7 +913,6 @@ const RelaySettingsPage: React.FC = () => { header={settings.mode !== 'smart' ? `Blacklisted Audio Extensions` : 'Audio Extensions'} key="5" > - <>{console.log(settings.mode)} {settings.mode !== 'unlimited' && settings.mode !== '' && (
@@ -824,23 +965,7 @@ const RelaySettingsPage: React.FC = () => { const mobileAndTabletLayout = ( - - {t('common.serverSetting')} - handleModeChange(e)} - /> - + {'Options'} @@ -948,7 +1073,125 @@ const RelaySettingsPage: React.FC = () => { + + + +
+ {settings.mode !== 'unlimited' && settings.mode !== '' && ( +
+ {}} //TODO handle change + /> +
+ )} + handleSettingsChange('kinds', checkedValues as string[])} + disabled={settings.mode !== 'smart' ? false : !settings.isKindsActive} + options={appBucketOptions} + /> + {settings.mode !== 'smart' && ( +
+

{'Add an App Bucket'}

+
+ {}} //TODO: handle changes + placeholder="Enter new app bucket" + /> + { + if (newKind) { + setSettings((prevSettings) => ({ + ...prevSettings, + dynamicKinds: [...(prevSettings.dynamicKinds || []), newKind], + })); + setNewKind(''); + } + }} + > + Add bucket + +
+ handleSettingsChange('dynamicKinds', checkedValues as string[])} + > + {(settings.dynamicKinds || []).map((kind) => ( +
+
+ + + {`kind` + kind} + +
+ removeDynamicKind(kind)} + > + Remove + +
+ ))} +
+
+ )} +
+
+
+
+ + {t('common.serverSetting')} + handleModeChange(e)} + /> + {

{group.name}

{group.notes.map((note) => ( -
+
{
{settings.mode === 'unlimited' && ( -
+

{'Add to Blacklist'}

-
+
setNewKind(e.target.value)} placeholder="Enter new kind" /> { if (newKind) { setSettings((prevSettings) => ({ + //TODO: don't allow duplicates ...prevSettings, dynamicKinds: [...(prevSettings.dynamicKinds || []), newKind], })); @@ -1026,7 +1272,7 @@ const RelaySettingsPage: React.FC = () => {
{ > {(settings.dynamicKinds || []).map((kind) => (
-
+
{ isActive={true} style={{ fontSize: '1.2rem', paddingRight: '.8rem', paddingLeft: '.8rem' }} > - {`kind`+kind} + {`kind` + kind}
removeDynamicKind(kind)}> @@ -1172,6 +1424,7 @@ const RelaySettingsPage: React.FC = () => { + {t('buttons.saveSettings')} diff --git a/src/pages/uiComponentsPages/UIComponentsPage.styles.ts b/src/pages/uiComponentsPages/UIComponentsPage.styles.ts index 7ee6e08..b7c7cfb 100644 --- a/src/pages/uiComponentsPages/UIComponentsPage.styles.ts +++ b/src/pages/uiComponentsPages/UIComponentsPage.styles.ts @@ -133,3 +133,7 @@ export const LabelSpan = styled.span` align-items: center; // Center align to match switch height padding-right: 10px; // Optional padding for visual spacing `; +export const HeadingContainer = styled.div` + +margin-bottom: 1.25rem; +`; \ No newline at end of file From dd665d8313336228310db2178202b864f11d57a1 Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:10:12 -0700 Subject: [PATCH 02/15] spacing fixes --- src/pages/RelaySettingsPage.tsx | 70 ++++++++++++++++----------------- src/styles/GlobalStyle.ts | 5 ++- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index 279e4e1..4df4b40 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -466,7 +466,9 @@ const RelaySettingsPage: React.FC = () => { - {'Options'} + + {'Options'} + @@ -564,12 +566,8 @@ const RelaySettingsPage: React.FC = () => { - - + +
{settings.mode !== 'unlimited' && settings.mode !== '' && ( @@ -583,8 +581,9 @@ const RelaySettingsPage: React.FC = () => {
)} handleSettingsChange('kinds', checkedValues as string[])} @@ -595,7 +594,7 @@ const RelaySettingsPage: React.FC = () => { {settings.mode !== 'smart' && (
{ >

{'Add an App Bucket'}

{ handleSettingsChange('dynamicKinds', checkedValues as string[])} > @@ -671,10 +670,10 @@ const RelaySettingsPage: React.FC = () => { { )} handleSettingsChange('kinds', checkedValues as string[])} disabled={settings.mode !== 'smart' ? false : !settings.isKindsActive} @@ -750,7 +749,7 @@ const RelaySettingsPage: React.FC = () => { {settings.mode !== 'smart' && (
{ >

{'Add to Blacklist'}

{ handleSettingsChange('dynamicKinds', checkedValues as string[])} > @@ -965,7 +964,9 @@ const RelaySettingsPage: React.FC = () => { const mobileAndTabletLayout = ( - {'Options'} + + {'Options'} + @@ -1074,11 +1075,7 @@ const RelaySettingsPage: React.FC = () => { - +
{settings.mode !== 'unlimited' && settings.mode !== '' && ( @@ -1093,7 +1090,9 @@ const RelaySettingsPage: React.FC = () => { )} handleSettingsChange('kinds', checkedValues as string[])} @@ -1111,10 +1110,7 @@ const RelaySettingsPage: React.FC = () => { }} >

{'Add an App Bucket'}

-
+
{}} //TODO: handle changes @@ -1137,8 +1133,8 @@ const RelaySettingsPage: React.FC = () => { handleSettingsChange('dynamicKinds', checkedValues as string[])} > @@ -1177,7 +1173,7 @@ const RelaySettingsPage: React.FC = () => { { style={{ padding: '0rem 0rem .5rem 0rem', display: 'flex', flexDirection: 'column', gap: '.5rem' }} >

{'Add to Blacklist'}

-
+
setNewKind(e.target.value)} placeholder="Enter new kind" /> { @@ -1274,8 +1270,8 @@ const RelaySettingsPage: React.FC = () => { handleSettingsChange('dynamicKinds', checkedValues as string[])} > diff --git a/src/styles/GlobalStyle.ts b/src/styles/GlobalStyle.ts index 9f172cc..5b9468a 100644 --- a/src/styles/GlobalStyle.ts +++ b/src/styles/GlobalStyle.ts @@ -260,6 +260,7 @@ export default createGlobalStyle` .checkboxHeader{ padding: 0rem 0 .5rem 0; } + .grid-checkbox-group { width: 100%; display: grid; @@ -281,7 +282,9 @@ export default createGlobalStyle` .checkbox-container{ white-space: nowrap; } - + .dynamic-group{ + padding-top: 1rem; + } .grid-checkbox-group.large-label { grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); } From 2377b355032fcfaf0323cc3e49bf6a5c8733533d Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:47:54 -0700 Subject: [PATCH 03/15] fixed spacing on bottom margin --- src/pages/RelaySettingsPage.tsx | 6 +++--- src/styles/GlobalStyle.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index 4df4b40..360f232 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -594,7 +594,7 @@ const RelaySettingsPage: React.FC = () => { {settings.mode !== 'smart' && (
{ {settings.mode !== 'smart' && (
{
{settings.mode === 'unlimited' && (

{'Add to Blacklist'}

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 = () => {
)} handleSettingsChange('kinds', checkedValues as string[])} @@ -715,7 +674,7 @@ const RelaySettingsPage: React.FC = () => {

{group.name}

{group.notes.map((note) => ( -
+
{ { if (newKind) { - setSettings((prevSettings) => ({ - /// TODO: don't allow duplicates - ...prevSettings, - dynamicKinds: [...(prevSettings.dynamicKinds || []), newKind], - })); + handleNewDynamicKind(newKind); setNewKind(''); } }} @@ -781,12 +736,12 @@ const RelaySettingsPage: React.FC = () => { handleSettingsChange('dynamicKinds', checkedValues as string[])} > - {(settings.dynamicKinds || []).map((kind) => ( + {(storedDynamicKinds || []).map((kind) => (
{
- {settings.mode !== 'unlimited' && settings.mode !== '' && ( -
- {}} //TODO handle change - /> -
- )} +
+ {}} //TODO handle change + /> +
handleSettingsChange('kinds', checkedValues as string[])} - disabled={settings.mode !== 'smart' ? false : !settings.isKindsActive} + style={{ padding: '1rem 0rem 1rem 1rem' }} + className={`custom-checkbox-group grid-mobile-checkbox-group `} + value={settings.appBuckets || []} + onChange={(checkedValues) => handleSettingsChange('appBuckets', checkedValues as string[])} + //disabled={settings.mode !== 'smart' ? false : !settings.isKindsActive} options={appBucketOptions} /> - {settings.mode !== 'smart' && ( -
+

{'Add an App Bucket'}

+
+ { + setNewBucket(e.target.value); + }} + placeholder="Enter new app bucket" + /> + { + if (newBucket) { + handleNewBucket(newBucket); + setNewKind(''); + } + }} + > + Add bucket + +
+ handleSettingsChange('dynamicAppBuckets', checkedValues as string[])} > -

{'Add an App Bucket'}

-
- {}} //TODO: handle changes - placeholder="Enter new app bucket" - /> - { - if (newKind) { - setSettings((prevSettings) => ({ - ...prevSettings, - dynamicKinds: [...(prevSettings.dynamicKinds || []), newKind], - })); - setNewKind(''); - } - }} + {(storedAppBuckets || []).map((bucket) => ( +
- Add bucket - -
- handleSettingsChange('dynamicKinds', checkedValues as string[])} - > - {(settings.dynamicKinds || []).map((kind) => ( -
-
- - - {`kind` + kind} - -
- removeDynamicKind(kind)} +
+ + - Remove - + {bucket} +
- ))} - -
- )} + handleRemovedBucket(bucket)} + > + Remove + +
+ ))} +
+
@@ -1244,20 +1188,14 @@ const RelaySettingsPage: React.FC = () => {
{settings.mode === 'unlimited' && ( -
+

{'Add to Blacklist'}

setNewKind(e.target.value)} placeholder="Enter new kind" /> { if (newKind) { - setSettings((prevSettings) => ({ - //TODO: don't allow duplicates - ...prevSettings, - dynamicKinds: [...(prevSettings.dynamicKinds || []), newKind], - })); + handleNewDynamicKind(newKind); setNewKind(''); } }} @@ -1269,11 +1207,11 @@ const RelaySettingsPage: React.FC = () => { style={{ paddingLeft: '.6rem' }} className={`custom-checkbox-group grid-checkbox-group large-label ${ settings.mode === 'unlimited' ? 'blacklist-mode-active ' : '' - }${settings.dynamicKinds?.length ? 'dynamic-group' : ''}`} + }${storedDynamicKinds?.length ? 'dynamic-group' : ''}`} value={settings.dynamicKinds || []} onChange={(checkedValues) => handleSettingsChange('dynamicKinds', checkedValues as string[])} > - {(settings.dynamicKinds || []).map((kind) => ( + {(storedDynamicKinds || []).map((kind) => (
Date: Fri, 2 Aug 2024 12:48:26 -0700 Subject: [PATCH 06/15] removed switches --- src/pages/RelaySettingsPage.tsx | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index 4cce9e7..f52b9ab 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -428,7 +428,7 @@ const RelaySettingsPage: React.FC = () => { updateDynamicKinds(); } }, [settings.dynamicKinds]); - + const desktopLayout = ( @@ -538,14 +538,6 @@ const RelaySettingsPage: React.FC = () => {
-
- {}} //TODO handle change - /> -
{
-
- {}} //TODO handle change - /> -
{ { if (newKind) { - handleNewDynamicKind(newKind); + handleNewDynamicKind(newKind); setNewKind(''); } }} From 8214e07d7567ce1c4a565195fbbf0ca0a8f9ea6b Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Sat, 17 Aug 2024 08:29:34 -0700 Subject: [PATCH 07/15] info card --- src/pages/RelaySettingsPage.tsx | 19 +++++++++++++- .../UIComponentsPage.styles.ts | 25 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index f52b9ab..a2f0bfb 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; -import { Collapse, Select, Input, Checkbox } from 'antd'; +import { Collapse, Select, Input, Checkbox, Typography } from 'antd'; import styled from 'styled-components'; import { BaseSwitch } from '@app/components/common/BaseSwitch/BaseSwitch'; import { BaseCheckbox } from '@app/components/common/BaseCheckbox/BaseCheckbox'; @@ -18,6 +18,7 @@ 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'; +import { InfoCircleOutlined } from '@ant-design/icons'; const { Panel } = Collapse; const StyledPanel = styled(Panel)``; const { Option } = Select; @@ -537,6 +538,14 @@ const RelaySettingsPage: React.FC = () => { + + + + { + 'Enabling buckets will organize data stored within the relay to quicken retrieval times for users. Disabling buckets will not turn off data storage.' + } + +
{ + + + + { + 'Enabling buckets will organize data stored within the relay to quicken retrieval times for users. Disabling buckets will not turn off data storage.' + } + +
Date: Mon, 26 Aug 2024 20:32:34 -0700 Subject: [PATCH 08/15] update infocard --- .env.development | 2 +- src/pages/RelaySettingsPage.tsx | 55 +++++++------------ .../UIComponentsPage.styles.ts | 29 +++++++--- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/.env.development b/.env.development index 5e5aec8..a9ee309 100644 --- a/.env.development +++ b/.env.development @@ -1,7 +1,7 @@ REACT_APP_BASE_URL=http://localhost:9002 # REACT_APP_BASE_URL=https://11561ba2d27f.ngrok.app REACT_APP_ASSETS_BUCKET=http://localhost -REACT_APP_DEMO_MODE=false +REACT_APP_DEMO_MODE=true # more info https://create-react-app.dev/docs/advanced-configuration ESLINT_NO_DEV_ERRORS=true diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index a2f0bfb..8a64c9c 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -538,14 +538,6 @@ const RelaySettingsPage: React.FC = () => { - - - - { - 'Enabling buckets will organize data stored within the relay to quicken retrieval times for users. Disabling buckets will not turn off data storage.' - } - -
{ options={appBucketOptions} /> -
+ + + + { + 'Enabling buckets will organize data stored within the relay to quicken retrieval times for users. Disabling buckets will not turn off data storage.' + } + + +

{'Add an App Bucket'}

{
))} -
+
@@ -1031,14 +1024,6 @@ const RelaySettingsPage: React.FC = () => { - - - - { - 'Enabling buckets will organize data stored within the relay to quicken retrieval times for users. Disabling buckets will not turn off data storage.' - } - -
{ //disabled={settings.mode !== 'smart' ? false : !settings.isKindsActive} options={appBucketOptions} /> - -
+ + + + { + 'Enabling buckets will organize data stored within the relay to quicken retrieval times for users. Disabling buckets will not turn off data storage.' + } + + +

{'Add an App Bucket'}

{
))} -
+
diff --git a/src/pages/uiComponentsPages/UIComponentsPage.styles.ts b/src/pages/uiComponentsPages/UIComponentsPage.styles.ts index 13c1afd..a72fccc 100644 --- a/src/pages/uiComponentsPages/UIComponentsPage.styles.ts +++ b/src/pages/uiComponentsPages/UIComponentsPage.styles.ts @@ -4,6 +4,7 @@ import { BaseCollapse } from '@app/components/common/BaseCollapse/BaseCollapse'; import { LAYOUT, media } from '@app/styles/themes/constants'; import { BaseCol } from '@app/components/common/BaseCol/BaseCol'; import { BaseSwitch } from '@app/components/common/BaseSwitch/BaseSwitch'; +import { InfoCircleOutlined } from '@ant-design/icons'; export const Card = styled(CommonCard)` width: 100%; margin-bottom: 1.25rem; @@ -26,20 +27,33 @@ export const Card = styled(CommonCard)` border: 1px solid var(--border-color); } `; +export const InfoCircleOutlinedIcon = styled(InfoCircleOutlined)` + color: var(--text-light-color); + font-size: 1rem; + cursor: pointer; +`; +export const NewBucketContainer = styled.div` + padding: 1rem 0rem 0rem 0rem; + display: flex; + flex-direction: column; + gap: 0.5rem; +`; export const InfoCard = styled(CommonCard)` - width: 100%; - + width: 100%; + padding-top: 1.5rem; + .ant-card-head-title { font-size: 1rem; } .ant-card-body { - flex-wrap: nowrap; + flex-wrap: nowrap; display: flex; flex-direction: row; gap: 0rem; - align-items: flex-start; - padding:0; + align-items: center; + + padding: 0; } .ant-card-body:before { display: none; @@ -159,6 +173,5 @@ export const LabelSpan = styled.span` padding-right: 10px; // Optional padding for visual spacing `; export const HeadingContainer = styled.div` - -margin-bottom: 1.25rem; -`; \ No newline at end of file + margin-bottom: 1.25rem; +`; From cf1033436e2259a9e92479672717984090debf9b Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:31:07 -0700 Subject: [PATCH 09/15] fixed app buckets icon --- src/pages/RelaySettingsPage.tsx | 6 +++--- src/pages/uiComponentsPages/UIComponentsPage.styles.ts | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index 8a64c9c..b2e2100 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -540,7 +540,7 @@ const RelaySettingsPage: React.FC = () => {
handleSettingsChange('appBuckets', checkedValues as string[])} options={appBucketOptions} @@ -548,7 +548,7 @@ const RelaySettingsPage: React.FC = () => { - + { 'Enabling buckets will organize data stored within the relay to quicken retrieval times for users. Disabling buckets will not turn off data storage.' } @@ -1035,7 +1035,7 @@ const RelaySettingsPage: React.FC = () => { /> - + { 'Enabling buckets will organize data stored within the relay to quicken retrieval times for users. Disabling buckets will not turn off data storage.' } diff --git a/src/pages/uiComponentsPages/UIComponentsPage.styles.ts b/src/pages/uiComponentsPages/UIComponentsPage.styles.ts index a72fccc..7a36cf0 100644 --- a/src/pages/uiComponentsPages/UIComponentsPage.styles.ts +++ b/src/pages/uiComponentsPages/UIComponentsPage.styles.ts @@ -29,7 +29,10 @@ export const Card = styled(CommonCard)` `; export const InfoCircleOutlinedIcon = styled(InfoCircleOutlined)` color: var(--text-light-color); - font-size: 1rem; + font-size: .75rem; + align-self: start; + padding-top .2rem; + padding-right: .5rem; cursor: pointer; `; export const NewBucketContainer = styled.div` @@ -40,8 +43,7 @@ export const NewBucketContainer = styled.div` `; export const InfoCard = styled(CommonCard)` width: 100%; - padding-top: 1.5rem; - + padding: 0.7rem 1.2rem; .ant-card-head-title { font-size: 1rem; } From c4f2a4e6504729d1dcdd0346194f59f1b7029fbd Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:44:07 -0700 Subject: [PATCH 10/15] fix issue with dynamic app buckets --- src/pages/RelaySettingsPage.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index b2e2100..46c243c 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -321,8 +321,9 @@ const RelaySettingsPage: React.FC = () => { return; } setStoredAppBuckets((prevBuckets) => [...prevBuckets, bucket]); - handleSettingsChange('appBuckets', [...settings.appBuckets, bucket]); + handleSettingsChange('dynamicAppBuckets', [...settings.dynamicAppBuckets, bucket]); }; + const handleRemovedBucket = (bucket: string) => { setStoredAppBuckets((prevBuckets) => prevBuckets.filter((b) => b !== bucket)); handleSettingsChange( From af96ceeeb86af885dd5cb9b8ec8170d6fdab59ce Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:29:17 -0700 Subject: [PATCH 11/15] fix: parsing error --- src/hooks/useRelaySettings.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/useRelaySettings.ts b/src/hooks/useRelaySettings.ts index 5583b9a..cf9fb28 100644 --- a/src/hooks/useRelaySettings.ts +++ b/src/hooks/useRelaySettings.ts @@ -74,8 +74,8 @@ const useRelaySettings = () => { 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)); + const newAppBuckets = !data.relaySettings.dynamicAppBuckets ? [] : data.relaySettings.dynamicAppBuckets.filter((bucket: string) => !storedAppBuckets.includes(bucket)); + const newDynamicKinds = !data.relaySettings.dynamicKinds ? [] : data.relaySettings.dynamicKinds.filter((kind :string) => !storedDynamicKinds.includes(kind)); if (newAppBuckets.length > 0) { localStorage.setItem('appBuckets', JSON.stringify([...storedAppBuckets, ...newAppBuckets])); From 8444cd842c162d515303e2d11e30c514ac5b6476 Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:31:42 -0700 Subject: [PATCH 12/15] chore: move state management --- src/pages/RelaySettingsPage.tsx | 58 ++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index 46c243c..080f48f 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -25,28 +25,12 @@ const { Option } = Select; const RelaySettingsPage: React.FC = () => { const theme = useAppSelector((state) => state.theme.theme); - const [loadings, setLoadings] = useState([]); - const enterLoading = (index: number) => { - setLoadings((loadings) => { - const newLoadings = [...loadings]; - newLoadings[index] = true; - return newLoadings; - }); - }; - - const exitLoading = (index: number) => { - setLoadings((loadings) => { - const newLoadings = [...loadings]; - newLoadings[index] = false; - return newLoadings; - }); - }; - const { relaySettings, fetchSettings, updateSettings, saveSettings } = useRelaySettings(); + const { isDesktop } = useResponsive(); const { t } = useTranslation(); const dispatch = useAppDispatch(); const relaymode = useAppSelector((state) => state.mode.relayMode); - const { isDesktop } = useResponsive(); + const [storedDynamicKinds, setStoredDynamicKinds] = useState( JSON.parse(localStorage.getItem('dynamicKinds') || '[]'), @@ -55,6 +39,17 @@ const RelaySettingsPage: React.FC = () => { JSON.parse(localStorage.getItem('appBuckets') || '[]'), ); + const [loadings, setLoadings] = useState([]); + const [newKind, setNewKind] = useState(''); + const [newBucket, setNewBucket] = useState(''); + const [blacklist, setBlacklist] = useState({ + kinds: [], + photos: [], + videos: [], + gitNestr: [], + audio: [], + }); + const [settings, setSettings] = useState({ mode: JSON.parse(localStorage.getItem('relaySettings') || '{}').mode || relaymode || 'unlimited', protocol: ['WebSocket'], @@ -81,6 +76,23 @@ const RelaySettingsPage: React.FC = () => { notes: noteOptions.filter((note) => note.category === category.id), })); + const enterLoading = (index: number) => { + setLoadings((loadings) => { + const newLoadings = [...loadings]; + newLoadings[index] = true; + return newLoadings; + }); + }; + + const exitLoading = (index: number) => { + setLoadings((loadings) => { + const newLoadings = [...loadings]; + newLoadings[index] = false; + return newLoadings; + }); + }; + + const photoFormatOptions = [ 'jpeg', 'jpg', @@ -213,15 +225,7 @@ 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: [], - videos: [], - gitNestr: [], - audio: [], - }); + const handleModeChange = (checked: boolean) => { const newMode = checked ? 'smart' : 'unlimited'; From f5ae20034f2a7df60e00f15dac518ea08f713543 Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:47:44 -0700 Subject: [PATCH 13/15] fix: incorrect field name --- src/hooks/useRelaySettings.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hooks/useRelaySettings.ts b/src/hooks/useRelaySettings.ts index cf9fb28..560246a 100644 --- a/src/hooks/useRelaySettings.ts +++ b/src/hooks/useRelaySettings.ts @@ -68,14 +68,20 @@ const useRelaySettings = () => { if (!response.ok) { throw new Error(`Network response was not ok (status: ${response.status})`); } - + const data = await response.json(); const storedAppBuckets = JSON.parse(localStorage.getItem('appBuckets') || '[]'); const storedDynamicKinds = JSON.parse(localStorage.getItem('dynamicKinds') || '[]'); - - const newAppBuckets = !data.relaySettings.dynamicAppBuckets ? [] : data.relaySettings.dynamicAppBuckets.filter((bucket: string) => !storedAppBuckets.includes(bucket)); - const newDynamicKinds = !data.relaySettings.dynamicKinds ? [] : data.relaySettings.dynamicKinds.filter((kind :string) => !storedDynamicKinds.includes(kind)); + console.log(data) + const newAppBuckets = + data.relay_settings.dynamicAppBuckets == undefined + ? [] + : data.relay_settings.dynamicAppBuckets.filter((bucket: string) => !storedAppBuckets.includes(bucket)); + const newDynamicKinds = + data.relay_settings.dynamicKinds == undefined + ? [] + : data.relay_settings.dynamicKinds.filter((kind: string) => !storedDynamicKinds.includes(kind)); if (newAppBuckets.length > 0) { localStorage.setItem('appBuckets', JSON.stringify([...storedAppBuckets, ...newAppBuckets])); From 9fc05353a75985a142d47df0573b18d9de736cae Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:25:23 -0700 Subject: [PATCH 14/15] fix: issue with blacklist --- src/pages/RelaySettingsPage.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index 080f48f..6fac00d 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -18,7 +18,6 @@ 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'; -import { InfoCircleOutlined } from '@ant-design/icons'; const { Panel } = Collapse; const StyledPanel = styled(Panel)``; const { Option } = Select; @@ -31,7 +30,6 @@ const RelaySettingsPage: React.FC = () => { const dispatch = useAppDispatch(); const relaymode = useAppSelector((state) => state.mode.relayMode); - const [storedDynamicKinds, setStoredDynamicKinds] = useState( JSON.parse(localStorage.getItem('dynamicKinds') || '[]'), ); @@ -76,6 +74,10 @@ const RelaySettingsPage: React.FC = () => { notes: noteOptions.filter((note) => note.category === category.id), })); + useEffect(() => { + console.log(settings); + console.log(blacklist) + }, [settings,blacklist]); const enterLoading = (index: number) => { setLoadings((loadings) => { const newLoadings = [...loadings]; @@ -92,7 +94,6 @@ const RelaySettingsPage: React.FC = () => { }); }; - const photoFormatOptions = [ 'jpeg', 'jpg', @@ -225,13 +226,11 @@ const RelaySettingsPage: React.FC = () => { const chunkSizeOptions = ['2', '4', '6', '8', '10', '12']; const maxFileSizeUnitOptions = ['MB', 'GB', 'TB']; - - const handleModeChange = (checked: boolean) => { const newMode = checked ? 'smart' : 'unlimited'; updateSettings('mode', newMode); dispatch(setMode(newMode)); - + console.log("changing mode") if (newMode === 'unlimited') { setBlacklist({ kinds: [], @@ -252,8 +251,11 @@ const RelaySettingsPage: React.FC = () => { }; const handleBlacklistChange = (category: Category, checkedValues: string[]) => { - const isDynamicKind = category === 'dynamicKinds' || 'appBuckets'; + console.log("changing blacklist") + debugger + const isDynamicKind = category === 'dynamicKinds' || category === 'appBuckets'; if (isDynamicKind) { + console.log("changing dynamic kind") setSettings((prevSettings) => { const updatedSettings = { ...prevSettings, [category]: checkedValues }; updateSettings(category, checkedValues); @@ -276,6 +278,7 @@ const RelaySettingsPage: React.FC = () => { }; const handleSettingsChange = (category: Category, checkedValues: string[]) => { + console.log("changing settings", category, checkedValues) if (settings.mode === 'unlimited') { handleBlacklistChange(category, checkedValues); } else { @@ -364,8 +367,8 @@ const RelaySettingsPage: React.FC = () => { updateSettings('chunked', settings.chunked), updateSettings('maxFileSize', settings.maxFileSize), updateSettings('maxFileSizeUnit', settings.maxFileSizeUnit), - updateSettings('appBuckets', settings.appBuckets), - updateSettings('dynamicAppBuckets', settings.dynamicAppBuckets), + // updateSettings('appBuckets', settings.appBuckets), + //updateSettings('dynamicAppBuckets', settings.dynamicAppBuckets), ]); await saveSettings(); @@ -409,6 +412,8 @@ const RelaySettingsPage: React.FC = () => { }, [relaySettings]); useEffect(() => { + if(settings.mode === 'unlimited') return + console.log("resetting blacklist changing") setBlacklist({ kinds: [], photos: [], From 10fe372c8b72d9ed4b644310156b8ed6464f66d9 Mon Sep 17 00:00:00 2001 From: TONE-E <90010906+AnthonyMarin@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:53:06 -0700 Subject: [PATCH 15/15] change labels to "relay settings" --- src/components/layouts/main/sider/sidebarNavigation.tsx | 4 ++-- src/components/router/AppRouter.tsx | 2 +- src/locales/en/translation.json | 4 ++-- src/pages/RelaySettingsPage.tsx | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/layouts/main/sider/sidebarNavigation.tsx b/src/components/layouts/main/sider/sidebarNavigation.tsx index 16d243d..3930882 100644 --- a/src/components/layouts/main/sider/sidebarNavigation.tsx +++ b/src/components/layouts/main/sider/sidebarNavigation.tsx @@ -27,8 +27,8 @@ export const useSidebarNavigation = (): SidebarNavigationItem[] => { }, { title: 'common.relay-settings', - key: 'storage-settings', - url: '/storage-settings', + key: 'relay-settings', + url: '/relay-settings', icon: , }, { diff --git a/src/components/router/AppRouter.tsx b/src/components/router/AppRouter.tsx index d3163dc..f4cb1fd 100644 --- a/src/components/router/AppRouter.tsx +++ b/src/components/router/AppRouter.tsx @@ -69,7 +69,7 @@ const Logout = React.lazy(() => import('./Logout')); export const NFT_DASHBOARD_PATH = '/'; export const MEDICAL_DASHBOARD_PATH = '/medical-dashboard'; -export const RELAY_SETTINGS_PATH = '/storage-settings'; +export const RELAY_SETTINGS_PATH = '/relay-settings'; export const TABLES_PAGE_PATH = '/nostr-stats'; const MedicalDashboard = withLoading(MedicalDashboardPage); diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index ec2a88d..8cd1ad1 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -224,7 +224,7 @@ "copied": "Copied to clipboard", "copy": "Copy", "country": "Country", - "customizeRelaySettings": "Storage Settings", + "customizeRelaySettings": "Relay Settings", "nft-dashboard": "Relay Dashboard", "medical-dashboard": "Medical Dashboard", "dataDisplay": "Data display", @@ -299,7 +299,7 @@ "radio": "Radio", "rate": "Rate", "reactSimpleMaps": "React Simple Maps", - "relay-settings": "Storage Settings", + "relay-settings": "Relay Settings", "relay-stats": "Relay Stats", "requiredField": "This field is required!", "resetPassword": "Reset password", diff --git a/src/pages/RelaySettingsPage.tsx b/src/pages/RelaySettingsPage.tsx index 6fac00d..1638b94 100644 --- a/src/pages/RelaySettingsPage.tsx +++ b/src/pages/RelaySettingsPage.tsx @@ -925,7 +925,7 @@ const RelaySettingsPage: React.FC = () => { {'Options'} - +