add view for single text

This commit is contained in:
Yisroel Baum 2026-04-17 09:22:55 +03:00
parent 5b2d85fb92
commit 68da48aedd
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 30 additions and 0 deletions

View file

@ -21,4 +21,12 @@ class ViewController
return $response; return $response;
} }
public function text(Response $response): Response
{
$html = file_get_contents(__DIR__.'/../../views/templates/text.php', true);
$response->getBody()->write($html);
return $response;
}
} }

View file

@ -14,8 +14,10 @@ $app->addErrorMiddleware(true, true, true);
$app->get('/admin', [ViewController::class, 'admin']); $app->get('/admin', [ViewController::class, 'admin']);
$app->get('/admin/texts', [ViewController::class, 'texts']); $app->get('/admin/texts', [ViewController::class, 'texts']);
$app->get('/admin/texts/{textId}', [ViewController::class, 'text']);
$app->get('/api/texts', [TextController::class, 'getTexts']); $app->get('/api/texts', [TextController::class, 'getTexts']);
$app->get('/api/texts/{textId}', [TextController::class, 'getText']);
$app->post('/api/texts', [TextController::class, 'createText']); $app->post('/api/texts', [TextController::class, 'createText']);
return $app; return $app;

9
public/js/text.js Normal file
View file

@ -0,0 +1,9 @@
document.addEventListener('DOMContentLoaded', () => {
const textId = window.location.pathname.split('/').pop();
fetch('/api/texts/' + textId)
.then(res => res.json())
.then(text => {
document.getElementById('text-detail').textContent = text.name;
});
});

11
views/templates/text.php Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Daily Goals - Text</title>
</head>
<body>
<a href="/admin/texts" id="back">Back to Texts</a>
<div id="text-detail"></div>
<script src="/js/text.js"></script>
</body>
</html>