Merge branch 'home-page'

This commit is contained in:
Yisroel Baum 2026-04-23 10:04:19 +03:00
commit 7084794c67
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
5 changed files with 54 additions and 0 deletions

View file

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

View file

@ -13,6 +13,7 @@ $app = Bridge::create($container);
// change first param to false for production
$app->addErrorMiddleware(true, true, true);
$app->get('/home', [ViewController::class, 'home']);
$app->get('/admin', [ViewController::class, 'admin']);
$app->get('/admin/texts', [ViewController::class, 'texts']);
$app->get('/admin/texts/{textId}', [ViewController::class, 'text']);

20
cypress/e2e/home.cy.js Normal file
View file

@ -0,0 +1,20 @@
describe('The home page', () => {
beforeEach(() => {
cy.exec('npm run db:seed')
})
afterEach(() => {
cy.exec('npm run db:wipe')
})
it('displays heading', () => {
cy.visit('/home')
cy.get('h1').should('contain', 'Home')
})
it('displays texts from api', () => {
cy.intercept('GET', '/api/texts').as('getTexts')
cy.visit('/home')
cy.wait('@getTexts')
cy.get('#texts-list').should('contain', 'Tanach')
})
})

13
public/js/home.js Normal file
View file

@ -0,0 +1,13 @@
document.addEventListener('DOMContentLoaded', () => {
const textsList = document.getElementById('texts-list');
async function loadTexts() {
const response = await fetch('/api/texts');
const texts = await response.json();
textsList.innerHTML = texts
.map(text => '<li>' + text.name + '</li>')
.join('');
}
loadTexts();
});

12
views/templates/home.php Normal file
View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Daily Goals - Home</title>
</head>
<body>
<h1>Home</h1>
<ul id="texts-list">
</ul>
<script src="/js/home.js"></script>
</body>
</html>