MCPcopy
hub / github.com/srcbookdev/srcbook / Settings

Function Settings

packages/web/src/routes/settings.tsx:27–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25import { toast } from 'sonner';
26
27function Settings() {
28 const { updateConfig: updateConfigContext, defaultLanguage, subscriptionEmail } = useSettings();
29
30 const isSubscribed = subscriptionEmail && subscriptionEmail !== 'dismissed';
31
32 const [email, setEmail] = useState<string>(isSubscribed ? subscriptionEmail : '');
33
34 const updateDefaultLanguage = (value: CodeLanguageType) => {
35 updateConfigContext({ defaultLanguage: value });
36 };
37
38 const { theme, toggleTheme } = useTheme();
39
40 const handleSubscribe = async () => {
41 try {
42 const response = await subscribeToMailingList(email);
43 if (response.success) {
44 await updateConfigContext({ subscriptionEmail: email });
45 toast.success('Subscribed successfully!');
46 } else {
47 toast.error('There was an error subscribing to the mailing list. Please try again later.');
48 }
49 } catch (error) {
50 toast.error('There was an error subscribing to the mailing list. Please try again later.');
51 console.error('Subscription error:', error);
52 }
53 };
54
55 return (
56 <div>
57 <h4 className="h4 mx-auto mb-6">Settings</h4>
58 <div className="space-y-10">
59 <div>
60 <h2 className="text-base font-medium">Theme</h2>
61 <label className="opacity-70 text-sm" htmlFor="theme-switch">
62 Select light or dark mode for the Srcbook app.
63 </label>
64 <div className="flex items-center gap-2 mt-2">
65 <Switch id="theme-switch" checked={theme === 'dark'} onCheckedChange={toggleTheme} />
66 <label htmlFor="theme-switch">
67 <span className="text-sm font-medium">Dark mode</span>
68 </label>
69 </div>
70 </div>
71
72 <div>
73 <h2 className="text-base font-medium">Default Language</h2>
74 <label className="opacity-70 block pb-3 text-sm" htmlFor="language-selector">
75 The default language to use when creating new Srcbooks.
76 </label>
77 <Select onValueChange={updateDefaultLanguage}>
78 <SelectTrigger id="language-selector" className="w-[180px]">
79 <SelectValue
80 placeholder={defaultLanguage === 'typescript' ? 'TypeScript' : 'JavaScript'}
81 />
82 </SelectTrigger>
83 <SelectContent>
84 <SelectItem value="typescript">TypeScript</SelectItem>

Callers

nothing calls this directly

Calls 2

useSettingsFunction · 0.90
useThemeFunction · 0.85

Tested by

no test coverage detected