Skip to content

Commit f409b2f

Browse files
Merge pull request #4 from CodeSignal/bugfix
fixed a color bug
2 parents 964dba3 + 88a3efa commit f409b2f

File tree

2 files changed

+84
-28
lines changed

2 files changed

+84
-28
lines changed

app.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@
7474
try {
7575
await saveSchemaToServer(schema, 'solution.json');
7676
lastSent = now; dirty = false;
77-
setStatus('Auto-saved to solution.json');
77+
setStatus('Changes saved');
7878
} catch (e) {
7979
// Ignore transient failures; we'll retry next tick
8080
console.error(e);
81-
setStatus('Auto-save failed (will retry)');
81+
setStatus('Save failed (will retry)');
8282
}
8383
}, 250); // check 4x per second; flush at >=1s since last send
8484

@@ -460,6 +460,26 @@
460460
}
461461
})();
462462

463+
// --- Theme change detection ---
464+
function setupThemeChangeListener() {
465+
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
466+
467+
function handleThemeChange() {
468+
// Re-render the diagram when theme changes to update table colors
469+
if (schema) {
470+
Diagram.renderSchema(svg, schema, selectedTableId, selectTable, selectColumn, selectedColId);
471+
}
472+
}
473+
474+
// Listen for theme changes
475+
mediaQuery.addEventListener('change', handleThemeChange);
476+
477+
// Also listen for the older 'addListener' method for broader browser support
478+
if (mediaQuery.addListener) {
479+
mediaQuery.addListener(handleThemeChange);
480+
}
481+
}
482+
463483
// --- boot
464484
(async function init() {
465485
try {
@@ -474,7 +494,7 @@
474494
} catch (err) {
475495
console.warn('initial_state.json not found or failed to load. Starting empty.', err);
476496
schema = makeEmptySchema('Untitled schema');
477-
setStatus('No initial_state.json found. Starting with an empty schema.');
497+
setStatus('Starting with a new schema');
478498
}
479499
} else {
480500
setStatus(`Loaded: ${schema.name}`);
@@ -490,6 +510,9 @@
490510
Diagram.enableDragging(svg, schema, save, () => selectedTableId, () => selectedColId, selectTable, selectColumn);
491511
Diagram.enablePanZoom(svg, () => { /* persist view? not necessary */ });
492512

513+
// Setup theme change detection
514+
setupThemeChangeListener();
515+
493516
// Pre-populate FK target selects
494517
UI.fillTables(fkToTable, schema);
495518
const first = schema.tables[0];

solution.json

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,106 @@
11
{
2-
"name": "Untitled schema",
2+
"version": "1.0",
3+
"name": "ShopDB",
34
"tables": [
45
{
5-
"id": "tbl_users_5jfh90d",
6+
"id": "tbl_users",
67
"name": "users",
78
"columns": [
89
{
9-
"id": "col_id_tp7z9eh",
10+
"id": "u_id",
1011
"name": "id",
1112
"type": "int",
1213
"nullable": false,
1314
"default": null
15+
},
16+
{
17+
"id": "u_email",
18+
"name": "email",
19+
"type": "varchar(255)",
20+
"nullable": false,
21+
"default": null
22+
},
23+
{
24+
"id": "u_name",
25+
"name": "name",
26+
"type": "varchar(255)",
27+
"nullable": false,
28+
"default": null
1429
}
1530
],
1631
"primaryKey": [
17-
"col_id_tp7z9eh"
32+
"u_id"
1833
],
1934
"uniqueConstraints": [
2035
{
21-
"id": "uq_obntuki",
36+
"id": "uq_users_email",
2237
"columns": [
23-
"col_id_tp7z9eh"
38+
"u_email"
2439
]
2540
}
2641
],
2742
"indexes": [],
2843
"position": {
29-
"x": 656,
30-
"y": 133
44+
"x": 500,
45+
"y": 6
3146
},
32-
"color": "white"
47+
"color": "green"
3348
},
3449
{
35-
"id": "tbl_wow_ntv1bum",
36-
"name": "peep",
50+
"id": "tbl_orders",
51+
"name": "orders****",
3752
"columns": [
3853
{
39-
"id": "col_id_w4l8ea5",
54+
"id": "o_id",
4055
"name": "id",
4156
"type": "int",
4257
"nullable": false,
4358
"default": null
4459
},
4560
{
46-
"id": "col_user_id_v0cqfey",
61+
"id": "o_user_id",
4762
"name": "user_id",
4863
"type": "int",
4964
"nullable": false,
5065
"default": null
66+
},
67+
{
68+
"id": "o_total",
69+
"name": "total",
70+
"type": "decimal(10,2)",
71+
"nullable": false,
72+
"default": "0.00"
5173
}
5274
],
5375
"primaryKey": [
54-
"col_id_w4l8ea5"
55-
],
56-
"uniqueConstraints": [
57-
{
58-
"id": "uq_54xxf1u",
59-
"columns": [
60-
"col_id_w4l8ea5"
61-
]
62-
}
76+
"o_id"
6377
],
78+
"uniqueConstraints": [],
6479
"indexes": [],
6580
"position": {
66-
"x": 304,
67-
"y": 223
81+
"x": 198,
82+
"y": -33
6883
},
6984
"color": "red"
7085
}
7186
],
72-
"foreignKeys": []
87+
"foreignKeys": [
88+
{
89+
"id": "fk_a1cw4cy",
90+
"from": {
91+
"table": "tbl_orders",
92+
"columns": [
93+
"o_user_id"
94+
]
95+
},
96+
"to": {
97+
"table": "tbl_users",
98+
"columns": [
99+
"u_id"
100+
]
101+
},
102+
"onDelete": "NO ACTION",
103+
"onUpdate": "NO ACTION"
104+
}
105+
]
73106
}

0 commit comments

Comments
 (0)