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
|
import { apiClient } from "./client";
import { ControlsData, SafetyControl } from "./types";
export async function getControlsData(): Promise<ControlsData> {
const deviceId = apiClient.getSelectedDeviceId();
if (!deviceId) {
// Return default controls if no device selected
return {
safetyControls: getDefaultControls(),
};
}
try {
const response = await apiClient.get<{
success: boolean;
safetyControls: SafetyControl[];
}>(`/parent/controls/${deviceId}`);
return {
safetyControls: response.safetyControls,
};
} catch (e) {
console.error("Failed to fetch controls data", e);
return {
safetyControls: getDefaultControls(),
};
}
}
export async function updateSafetyControl(
key: string,
value: boolean
): Promise<void> {
const deviceId = apiClient.getSelectedDeviceId();
if (!deviceId) {
console.warn("No device selected, cannot update control");
return;
}
try {
await apiClient.post(`/parent/controls/${deviceId}`, { key, value });
} catch (e) {
console.error(`Failed to update ${key}`, e);
throw e;
}
}
function getDefaultControls(): SafetyControl[] {
return [
{
key: "disable_buddy",
title: "Disable Buddy",
description: "Temporarily disable Buddy",
defaultValue: false,
},
{
key: "adult_sites",
title: "Adult sites",
description: "Block adult websites.",
defaultValue: true,
},
{
key: "family_link_anti_circumvention",
title: "Anti-Circumvention",
description: "Prevent disabling of Family Link protections.",
defaultValue: false,
},
{
key: "filtering",
title: "Content filtering",
description: "Block unsafe or adult content.",
defaultValue: true,
},
{
key: "new_people",
title: "New contact alerts",
description: "Get notified when your child chats with someone new.",
defaultValue: true,
},
{
key: "block_strangers",
title: "Block communications with strangers",
description: "Block or scan communications with strangers.",
defaultValue: false,
},
{
key: "notify_dangerous_messages",
title: "Dangerous messages notifications",
description: "Notify when messages are potentially dangerous.",
defaultValue: true,
},
{
key: "notify_new_contact_added",
title: "New contact added notifications",
description: "Notify when a new contact is added.",
defaultValue: true,
},
];
}
|