-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAdvancedSettingsLayout.tsx
More file actions
167 lines (147 loc) · 5.48 KB
/
AdvancedSettingsLayout.tsx
File metadata and controls
167 lines (147 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import React, { useState } from 'react';
import { Button, Space, Spin } from 'antd';
import { LiquidBlueButton } from '@app/components/common/LiquidBlueButton';
import { BaseRow } from '@app/components/common/BaseRow/BaseRow';
import GeneralSettingsPanel from '../panels/GeneralSettingsPanel';
import ImageModerationPanel from '../panels/ImageModerationPanel';
import ContentFilterPanel from '../panels/ContentFilterPanel';
import OllamaPanel from '../panels/OllamaPanel';
import WalletPanel from '../panels/WalletPanel';
import PushNotificationPanel from '../panels/PushNotificationPanel';
import useGenericSettings from '@app/hooks/useGenericSettings';
import { CollapsibleSection } from '@app/components/relay-settings/shared/CollapsibleSection/CollapsibleSection';
import { Balance } from '@app/components/relay-dashboard/Balance/Balance';
import { TotalEarning } from '@app/components/relay-dashboard/totalEarning/TotalEarning';
import { ActivityStory } from '@app/components/relay-dashboard/transactions/Transactions';
import * as S from './AdvancedSettingsLayout.styles';
interface AdvancedSettingsLayoutProps {
loading?: boolean;
error?: string | null;
}
const AdvancedSettingsLayout: React.FC<AdvancedSettingsLayoutProps> = ({
loading: propLoading,
error: propError,
}) => {
const [saveLoading, setSaveLoading] = useState(false);
const [resetLoading, setResetLoading] = useState(false);
// Use the generic settings hook to handle saving all settings
const {
loading: hookLoading,
error: hookError,
saveSettings,
fetchSettings
} = useGenericSettings('general'); // We just need a hook instance for the save/fetch methods
const loading = propLoading || hookLoading;
const error = propError || (hookError ? hookError.toString() : null);
const handleSave = async () => {
console.log('Saving all settings...');
setSaveLoading(true);
try {
await saveSettings();
console.log('Settings saved successfully');
// Reset all forms by triggering their submit handlers
// This will reset the isUserEditing flag in all panel components
const formElements = document.querySelectorAll('form');
formElements.forEach(form => {
const submitEvent = new Event('submit', { bubbles: true, cancelable: true });
form.dispatchEvent(submitEvent);
});
// Also dispatch a custom event that the panel components can listen for
const saveEvent = new CustomEvent('settings-saved');
document.dispatchEvent(saveEvent);
} catch (error) {
console.error('Error saving settings:', error);
} finally {
setSaveLoading(false);
}
};
const handleReset = async () => {
console.log('Resetting all settings...');
setResetLoading(true);
try {
await fetchSettings();
console.log('Settings reset successfully');
} catch (error) {
console.error('Error resetting settings:', error);
} finally {
setResetLoading(false);
}
};
if (loading) {
return (
<div style={{ textAlign: 'center', padding: '2rem' }}>
<Spin size="large" />
<p>Loading settings...</p>
</div>
);
}
if (error) {
return (
<div style={{ textAlign: 'center', padding: '2rem', color: 'red' }}>
<p>Error loading settings: {error}</p>
<Button onClick={handleReset}>Try Again</Button>
</div>
);
}
return (
<S.DashboardWrapper>
<BaseRow>
<S.LeftSideCol xl={16} xxl={17} id="desktop-content">
<CollapsibleSection header="General Settings">
<GeneralSettingsPanel />
</CollapsibleSection>
<CollapsibleSection header="Image Moderation">
<ImageModerationPanel />
</CollapsibleSection>
<CollapsibleSection header="Content Filter">
<ContentFilterPanel />
</CollapsibleSection>
<CollapsibleSection header="Ollama">
<OllamaPanel />
</CollapsibleSection>
<CollapsibleSection header="Wallet">
<WalletPanel />
</CollapsibleSection>
<CollapsibleSection header="Push Notifications">
<PushNotificationPanel />
</CollapsibleSection>
<div style={{ marginTop: '2rem', display: 'flex', justifyContent: 'center' }}>
<Space size="middle">
<LiquidBlueButton
variant="primary"
size="large"
onClick={handleSave}
loading={saveLoading}
>
Save All Settings
</LiquidBlueButton>
<Button
size="large"
onClick={handleReset}
loading={resetLoading}
>
Reset
</Button>
</Space>
</div>
</S.LeftSideCol>
<S.RightSideCol xl={8} xxl={7}>
<div style={{ width: '100%', padding: '0 2rem', display: 'flex', flexDirection: 'column' }}>
<div id="balance" className="liquid-element">
<Balance />
</div>
<S.Space />
<div id="total-earning" className="liquid-element">
<TotalEarning />
</div>
<S.Space />
<div id="activity-story" className="liquid-element">
<ActivityStory />
</div>
</div>
</S.RightSideCol>
</BaseRow>
</S.DashboardWrapper>
);
};
export default AdvancedSettingsLayout;