MCPcopy Create free account
hub / github.com/TanStack/db / TodoApp

Function TodoApp

examples/solid/todo/src/components/TodoApp.tsx:15–280  ·  view source on GitHub ↗
(props: TodoAppProps)

Source from the content-addressed store, hash-verified

13}
14
15export function TodoApp(props: TodoAppProps) {
16 const [newTodo, setNewTodo] = createSignal(``)
17
18 // Define a type-safe helper function to get config values
19 const getConfigValue = (key: string): string => {
20 for (const config of props.configData) {
21 if (config.key === key) {
22 return config.value
23 }
24 }
25 return ``
26 }
27
28 // Define a helper function to update config values
29 const setConfigValue = (key: string, value: string): void => {
30 for (const config of props.configData) {
31 if (config.key === key) {
32 props.configCollection.update(config.id, (draft) => {
33 draft.value = value
34 })
35 return
36 }
37 }
38
39 // If the config doesn't exist yet, create it
40 props.configCollection.insert({
41 id: Math.round(Math.random() * 1000000),
42 key,
43 value,
44 created_at: new Date(),
45 updated_at: new Date(),
46 })
47 }
48
49 const backgroundColor = getConfigValue(`backgroundColor`)
50
51 // Function to generate a complementary color
52 const getComplementaryColor = (hexColor: string): string => {
53 // Default to a nice blue if no color is provided
54 if (!hexColor) return `#3498db`
55
56 // Remove the hash if it exists
57 const color = hexColor.replace(`#`, ``)
58
59 // Convert hex to RGB
60 const r = parseInt(color.substr(0, 2), 16)
61 const g = parseInt(color.substr(2, 2), 16)
62 const b = parseInt(color.substr(4, 2), 16)
63
64 // Calculate complementary color (inverting the RGB values)
65 const compR = 255 - r
66 const compG = 255 - g
67 const compB = 255 - b
68
69 // Convert back to hex
70 const compHex =
71 `#` +
72 ((1 << 24) + (compR << 16) + (compG << 8) + compB).toString(16).slice(1)

Callers

nothing calls this directly

Calls 7

filterMethod · 0.80
getConfigValueFunction · 0.70
getComplementaryColorFunction · 0.70
updateMethod · 0.45
mapMethod · 0.45
forEachMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected