diff --git a/app/View/ViewController.php b/app/View/ViewController.php index 0ee00ea..580c53e 100644 --- a/app/View/ViewController.php +++ b/app/View/ViewController.php @@ -21,4 +21,12 @@ class ViewController return $response; } + + public function text(Response $response): Response + { + $html = file_get_contents(__DIR__.'/../../views/templates/text.php', true); + $response->getBody()->write($html); + + return $response; + } } diff --git a/bootstrap/app.php b/bootstrap/app.php index ddc3dcd..9022386 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -14,8 +14,10 @@ $app->addErrorMiddleware(true, true, true); $app->get('/admin', [ViewController::class, 'admin']); $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/{textId}', [TextController::class, 'getText']); $app->post('/api/texts', [TextController::class, 'createText']); return $app; diff --git a/public/js/text.js b/public/js/text.js new file mode 100644 index 0000000..9c981d3 --- /dev/null +++ b/public/js/text.js @@ -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; + }); +}); diff --git a/views/templates/text.php b/views/templates/text.php new file mode 100644 index 0000000..8f68729 --- /dev/null +++ b/views/templates/text.php @@ -0,0 +1,11 @@ + + + + Daily Goals - Text + + + Back to Texts +
+ + +