Skip to content

Commit 5f32e60

Browse files
committed
Updating relay settings type and supporting code for file storage
1 parent 50a3bde commit 5f32e60

3 files changed

Lines changed: 40 additions & 205 deletions

File tree

src/constants/relaySettings.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
export type Settings = {
22
mode: string;
33
protocol: string[];
4-
chunked: string[];
5-
chunksize: string;
6-
maxFileSize: number;
7-
maxFileSizeUnit: string;
84
kinds: string[];
95
dynamicKinds: string[];
106
photos: string[];
@@ -18,6 +14,7 @@ export type Settings = {
1814
isVideosActive: boolean;
1915
isGitNestrActive: boolean;
2016
isAudioActive: boolean;
17+
isFileStorageActive: boolean;
2118
};
2219

2320
export type Category = 'kinds' | 'photos' | 'videos' | 'gitNestr' | 'audio' | 'dynamicKinds' | 'appBuckets' | 'dynamicAppBuckets';

src/hooks/useRelaySettings.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import { useHandleLogout } from './authUtils';
66
interface RelaySettings {
77
mode: string;
88
protocol: string[];
9-
chunked: string[];
10-
chunksize: string;
11-
maxFileSize: number;
12-
maxFileSizeUnit: string;
139
kinds: string[];
1410
dynamicKinds: string[];
1511
photos: string[];
@@ -23,6 +19,7 @@ interface RelaySettings {
2319
isVideosActive: boolean;
2420
isGitNestrActive: boolean;
2521
isAudioActive: boolean;
22+
isFileStorageActive: boolean;
2623
}
2724

2825
const getInitialSettings = (): RelaySettings => {
@@ -32,10 +29,6 @@ const getInitialSettings = (): RelaySettings => {
3229
: {
3330
mode: 'smart',
3431
protocol: ['WebSocket'],
35-
chunked: ['unchunked'],
36-
chunksize: '2',
37-
maxFileSize: 100,
38-
maxFileSizeUnit: 'MB',
3932
dynamicKinds: [],
4033
kinds: [],
4134
photos: [],
@@ -49,6 +42,7 @@ const getInitialSettings = (): RelaySettings => {
4942
isVideosActive: true,
5043
isGitNestrActive: true,
5144
isAudioActive: true,
45+
isFileStorageActive: false,
5246
};
5347
};
5448

@@ -72,7 +66,7 @@ const useRelaySettings = () => {
7266
'Authorization': `Bearer ${token}`,
7367
},
7468
});
75-
if (response.status === 401 ) {
69+
if (response.status === 401) {
7670
console.error('Unauthorized: Invalid or expired token');
7771
handleLogout();
7872
}
@@ -84,7 +78,7 @@ const useRelaySettings = () => {
8478

8579
const storedAppBuckets = JSON.parse(localStorage.getItem('appBuckets') || '[]');
8680
const storedDynamicKinds = JSON.parse(localStorage.getItem('dynamicKinds') || '[]');
87-
console.log(data)
81+
8882
const newAppBuckets =
8983
data.relay_settings.dynamicAppBuckets == undefined
9084
? []
@@ -105,9 +99,6 @@ const useRelaySettings = () => {
10599
protocol: Array.isArray(data.relay_settings.protocol)
106100
? data.relay_settings.protocol
107101
: [data.relay_settings.protocol],
108-
chunked: Array.isArray(data.relay_settings.chunked)
109-
? data.relay_settings.chunked
110-
: [data.relay_settings.chunked],
111102
});
112103
localStorage.setItem('relaySettings', JSON.stringify(data.relay_settings));
113104
} catch (error) {

src/pages/RelaySettingsPage.tsx

Lines changed: 35 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ const RelaySettingsPage: React.FC = () => {
5151
const [settings, setSettings] = useState<Settings>({
5252
mode: JSON.parse(localStorage.getItem('relaySettings') || '{}').mode || relaymode || 'unlimited',
5353
protocol: ['WebSocket'],
54-
chunked: ['unchunked'],
55-
chunksize: '2',
56-
maxFileSize: 100,
57-
maxFileSizeUnit: 'MB',
5854
kinds: [],
5955
dynamicKinds: [],
6056
photos: [],
@@ -68,7 +64,9 @@ const RelaySettingsPage: React.FC = () => {
6864
isVideosActive: true,
6965
isGitNestrActive: true,
7066
isAudioActive: true,
67+
isFileStorageActive: false,
7168
});
69+
7270
const groupedNoteOptions = categories.map((category) => ({
7371
...category,
7472
notes: noteOptions.filter((note) => note.category === category.id),
@@ -269,18 +267,21 @@ const RelaySettingsPage: React.FC = () => {
269267
}));
270268
};
271269

272-
const handleChunkedChange = (checkedValues: string[]) => {
273-
setSettings((prevSettings) => ({
274-
...prevSettings,
275-
chunked: checkedValues,
276-
}));
277-
updateSettings('chunked', checkedValues);
278-
};
270+
// const handleChunkedChange = (checkedValues: string[]) => {
271+
// setSettings((prevSettings) => ({
272+
// ...prevSettings,
273+
// chunked: checkedValues,
274+
// }));
275+
// updateSettings('chunked', checkedValues);
276+
// };
279277

280278
const handleSettingsChange = (category: Category, checkedValues: string[]) => {
281279
console.log("changing settings", category, checkedValues)
282280
if (settings.mode === 'unlimited') {
283-
handleBlacklistChange(category, checkedValues);
281+
setBlacklist((prevBlacklist) => ({
282+
...prevBlacklist,
283+
[category]: checkedValues,
284+
}));
284285
} else {
285286
setSettings((prevSettings) => {
286287
const updatedSettings = { ...prevSettings, [category]: checkedValues };
@@ -298,30 +299,6 @@ const RelaySettingsPage: React.FC = () => {
298299
updateSettings(category, value);
299300
};
300301

301-
const handleChunkSizeChange = (value: string) => {
302-
setSettings((prevSettings) => ({
303-
...prevSettings,
304-
chunksize: value,
305-
}));
306-
updateSettings('chunksize', value);
307-
};
308-
309-
const handleMaxFileSizeChange = (value: number) => {
310-
setSettings((prevSettings) => ({
311-
...prevSettings,
312-
maxFileSize: value,
313-
}));
314-
updateSettings('maxFileSize', value);
315-
};
316-
317-
const handleMaxFileSizeUnitChange = (value: string) => {
318-
setSettings((prevSettings) => ({
319-
...prevSettings,
320-
maxFileSizeUnit: value,
321-
}));
322-
updateSettings('maxFileSizeUnit', value);
323-
};
324-
325302
const handleNewBucket = (bucket: string) => {
326303
const currentBuckets = settings.appBuckets.concat(storedAppBuckets);
327304
if (currentBuckets.includes(bucket)) {
@@ -364,9 +341,7 @@ const RelaySettingsPage: React.FC = () => {
364341
updateSettings('gitNestr', settings.isGitNestrActive ? settings.gitNestr : []),
365342
updateSettings('audio', settings.isAudioActive ? settings.audio : []),
366343
updateSettings('protocol', settings.protocol),
367-
updateSettings('chunked', settings.chunked),
368-
updateSettings('maxFileSize', settings.maxFileSize),
369-
updateSettings('maxFileSizeUnit', settings.maxFileSizeUnit),
344+
updateSettings('isFileStorageActive', settings.isFileStorageActive),
370345
// updateSettings('appBuckets', settings.appBuckets),
371346
//updateSettings('dynamicAppBuckets', settings.dynamicAppBuckets),
372347
]);
@@ -401,12 +376,15 @@ const RelaySettingsPage: React.FC = () => {
401376
fetchSettings();
402377
}, [fetchSettings]);
403378

379+
useEffect(() => {
380+
fetchSettings();
381+
}, [fetchSettings]);
382+
404383
useEffect(() => {
405384
if (relaySettings) {
406385
setSettings({
407386
...relaySettings,
408387
protocol: Array.isArray(relaySettings.protocol) ? relaySettings.protocol : [relaySettings.protocol],
409-
chunked: Array.isArray(relaySettings.chunked) ? relaySettings.chunked : [relaySettings.chunked],
410388
});
411389
}
412390
}, [relaySettings]);
@@ -464,83 +442,21 @@ const RelaySettingsPage: React.FC = () => {
464442
onChange={(checkedValues) => handleProtocolChange(checkedValues as string[])}
465443
style={{
466444
display: 'grid',
467-
gridTemplateColumns: '10rem auto', // Adjust the width as needed
445+
gridTemplateColumns: '10rem auto',
468446
}}
469447
/>
470448
</div>
471449
<div style={{ borderTop: '1px solid #ccc', margin: '1rem 0' }}></div>
472450
<div style={{ display: 'flex', flexDirection: 'column' }}>
473-
<S.LabelSpan style={{ marginBottom: '1rem' }}>{t('common.chunkedSetting')}</S.LabelSpan>{' '}
474-
<Checkbox.Group
475-
className="custom-checkbox-group"
476-
options={[
477-
{ label: `Unchunked \u{1F338}`, value: 'unchunked', style: { fontSize: '.85rem' } },
478-
{ label: `Chunked \u{1F333}`, value: 'chunked', style: { fontSize: '.85rem' } },
479-
]}
480-
value={settings.chunked}
481-
onChange={(checkedValues) => handleChunkedChange(checkedValues as string[])}
482-
style={{
483-
display: 'grid',
484-
gridTemplateColumns: '10rem auto', // Adjust the width as needed
485-
}}
486-
/>
451+
<S.LabelSpan style={{ marginBottom: '1rem' }}>{t('File Storage')}</S.LabelSpan>{' '}
452+
<BaseCheckbox
453+
checked={settings.isFileStorageActive}
454+
onChange={(e) => handleSwitchChange('isFileStorageActive', e.target.checked)}
455+
style={{ fontSize: '.85rem' }}
456+
>
457+
Enable/Disable
458+
</BaseCheckbox>
487459
</div>
488-
{settings.chunked.includes('unchunked') && (
489-
<>
490-
<div style={{ marginTop: '1.5rem' }}>
491-
<strong>Max Unchunked File Size:</strong>
492-
<S.Space />
493-
</div>
494-
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginTop: '0.5rem' }}>
495-
<Input
496-
type="number"
497-
value={settings.maxFileSize}
498-
onChange={(e) => handleMaxFileSizeChange(Number(e.target.value))}
499-
style={{ width: 100 }}
500-
/>
501-
<Select
502-
className="custom-dropdown"
503-
value={settings.maxFileSizeUnit}
504-
onChange={handleMaxFileSizeUnitChange}
505-
style={{ width: 100 }}
506-
>
507-
{maxFileSizeUnitOptions.map((unit) => (
508-
<Option key={unit} value={unit}>
509-
{unit}
510-
</Option>
511-
))}
512-
</Select>
513-
</div>
514-
</>
515-
)}
516-
{settings.chunked.includes('chunked') && (
517-
<>
518-
<div style={{ marginTop: '1rem' }}>
519-
<strong>Max Chunked File Size:</strong>
520-
<S.Space />
521-
</div>
522-
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginTop: '0.5rem' }}>
523-
<Input
524-
type="number"
525-
value={settings.maxFileSize}
526-
onChange={(e) => handleMaxFileSizeChange(Number(e.target.value))}
527-
style={{ width: 100 }}
528-
/>
529-
<Select
530-
className="custom-dropdown"
531-
value={settings.maxFileSizeUnit}
532-
onChange={handleMaxFileSizeUnitChange}
533-
style={{ width: 100 }}
534-
>
535-
{maxFileSizeUnitOptions.map((unit) => (
536-
<Option key={unit} value={unit}>
537-
{unit}
538-
</Option>
539-
))}
540-
</Select>
541-
</div>
542-
</>
543-
)}
544460
</BaseCol>
545461
</S.Card>
546462
</StyledPanel>
@@ -949,83 +865,14 @@ const RelaySettingsPage: React.FC = () => {
949865
</div>
950866
<div style={{ borderTop: '1px solid #ccc', margin: '1rem 0' }}></div>
951867
<div style={{ display: 'flex', flexDirection: 'column' }}>
952-
<S.LabelSpan style={{ marginBottom: '0.5rem' }}>{t('common.chunkedSetting')}</S.LabelSpan>
953-
<Checkbox.Group
954-
className="custom-checkbox-group"
955-
options={[
956-
{
957-
label: `Unchunked \u{1F338}`,
958-
value: 'unchunked',
959-
style: { fontSize: '.8rem' },
960-
},
961-
{ label: `Chunked \u{1F333}`, value: 'chunked', style: { fontSize: '.8rem' } },
962-
]}
963-
value={settings.chunked}
964-
onChange={(checkedValues) => handleChunkedChange(checkedValues as string[])}
965-
style={{
966-
display: 'grid',
967-
gridTemplateColumns: '9rem auto',
968-
paddingRight: '0',
969-
justifyContent: 'start',
970-
fontSize: 'small',
971-
}}
972-
/>
973-
{settings.chunked.includes('unchunked') && (
974-
<>
975-
<div style={{ marginTop: '1rem' }}>
976-
<strong>Max Unchunked File Size:</strong>
977-
<S.Space />
978-
</div>
979-
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginTop: '0.5rem' }}>
980-
<Input
981-
type="number"
982-
value={settings.maxFileSize}
983-
onChange={(e) => handleMaxFileSizeChange(Number(e.target.value))}
984-
style={{ width: 100 }}
985-
/>
986-
<Select
987-
className="custom-dropdown"
988-
value={settings.maxFileSizeUnit}
989-
onChange={handleMaxFileSizeUnitChange}
990-
style={{ width: 100 }}
991-
>
992-
{maxFileSizeUnitOptions.map((unit) => (
993-
<Option key={unit} value={unit}>
994-
{unit}
995-
</Option>
996-
))}
997-
</Select>
998-
</div>
999-
</>
1000-
)}
1001-
{settings.chunked.includes('chunked') && (
1002-
<>
1003-
<div style={{ marginTop: '1rem' }}>
1004-
<strong>Max Chunked File Size:</strong>
1005-
<S.Space />
1006-
</div>
1007-
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginTop: '0.5rem' }}>
1008-
<Input
1009-
type="number"
1010-
value={settings.maxFileSize}
1011-
onChange={(e) => handleMaxFileSizeChange(Number(e.target.value))}
1012-
style={{ width: 100 }}
1013-
/>
1014-
<Select
1015-
className="custom-dropdown"
1016-
value={settings.maxFileSizeUnit}
1017-
onChange={handleMaxFileSizeUnitChange}
1018-
style={{ width: 100 }}
1019-
>
1020-
{maxFileSizeUnitOptions.map((unit) => (
1021-
<Option key={unit} value={unit}>
1022-
{unit}
1023-
</Option>
1024-
))}
1025-
</Select>
1026-
</div>
1027-
</>
1028-
)}
868+
<S.LabelSpan style={{ marginBottom: '0.5rem' }}>{t('File Storage')}</S.LabelSpan>
869+
<BaseCheckbox
870+
checked={settings.isFileStorageActive}
871+
onChange={(e) => handleSwitchChange('isFileStorageActive', e.target.checked)}
872+
style={{ fontSize: '.8rem' }}
873+
>
874+
Enable/Disable
875+
</BaseCheckbox>
1029876
</div>
1030877
</BaseCol>
1031878
</S.Card>

0 commit comments

Comments
 (0)