feat(ui): complete look and feel refactor with dark and light mode support
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Fociz Thema API Endpoint (Dark / Light / System)
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
require_once __DIR__ . '/../includes/auth.php';
|
||||
|
||||
$user = require_auth(true);
|
||||
$userId = (int)$user['id'];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$currentTheme = get_user_theme($userId);
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'theme' => $currentTheme,
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$raw = file_get_contents('php://input');
|
||||
$data = json_decode($raw, true);
|
||||
|
||||
$theme = $data['theme'] ?? ($_POST['theme'] ?? 'dark');
|
||||
if (!in_array($theme, ['dark', 'light', 'system'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'Ongeldig thema. Kies dark, light of system.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$ok = update_user_theme($userId, $theme);
|
||||
if ($ok) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'theme' => $theme,
|
||||
'message' => 'Themavoorkeur succesvol opgeslagen.',
|
||||
]);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => 'Kon thema niet opslaan in database.']);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
http_response_code(405);
|
||||
echo json_encode(['success' => false, 'error' => 'Method not allowed']);
|
||||
Reference in New Issue
Block a user