test route

This commit is contained in:
Matthis FAUVET 2024-06-28 23:59:56 +02:00
parent 4c9af83342
commit 86d1984095
3 changed files with 74 additions and 23 deletions

View File

@ -7,24 +7,58 @@
</head> </head>
<body class="bg-neutral-50"> <body class="bg-neutral-50">
<onzer></onzer> <div id="app"></div>
<script src="https://unpkg.com/animore/animore.js"></script> <script src="https://unpkg.com/animore/animore.js"></script>
<script src="https://unpkg.com/riot@9/riot+compiler.min.js"></script> <script src="https://unpkg.com/riot@9/riot+compiler.min.js"></script>
<script src="https://unpkg.com/@riotjs/route@6/route.umd.js"></script>
<!-- Composant Onzer -->
<script type="riot" src="./onzer.riot"></script> <script type="riot" src="./onzer.riot"></script>
<!-- Composant Playlists -->
<script type="riot">
<playlists>
<h1>Playlists Page</h1>
<p>This is the playlists page. It is currently empty.</p>
<script>
export default {
// Your component logic here
}
</script>
<style>
/* Your style here */
</style>
</playlists>
</script>
<script type="text/javascript"> <script type="text/javascript">
async function fetch_data() { async function fetch_data() {
return fetch("https://dwarves.iut-fbleau.fr/~fauvet/api/albums").then(response => { return fetch("https://dwarves.iut-fbleau.fr/~fauvet/api/albums").then(response => response.json());
return response.json(); }
});
function mountComponent(component) {
const app = document.getElementById('app');
app.innerHTML = '';
riot.mount(app, component);
} }
riot.compile().then(async () => { riot.compile().then(async () => {
const data = await fetch_data(); const data = await fetch_data();
// Définir les routes
route('/', () => {
riot.mount('onzer', { items: data }); riot.mount('onzer', { items: data });
}); });
route('/playlists', () => {
riot.mount('playlists');
});
// Démarrer le routeur
router.start();
router.exec();
});
</script> </script>
</body> </body>

View File

@ -13,7 +13,7 @@
<div class="flex flex-row items-baseline"> <div class="flex flex-row items-baseline">
<input class="flex-grow-1 border-solid border bg-emerald-100 w-half rounded-lg border-emerald-300 h-20 pl-6 grow" <input class="flex-grow-1 border-solid border bg-emerald-100 w-half rounded-lg border-emerald-300 h-20 pl-6 grow"
placeholder={state.placeholder} onkeyup={edit} /> placeholder={state.placeholder} onkeyup={edit} />
<input type="button" value="Playlists" <input type="button" value="Playlists" onclick={navigateToPlaylists}
class="ml-2 border-solid bg-emerald-300 border rounded-lg border-emerald-600 mb-4 h-20 w-48 mt-2" /> class="ml-2 border-solid bg-emerald-300 border rounded-lg border-emerald-600 mb-4 h-20 w-48 mt-2" />
</div> </div>
</form> </form>
@ -96,6 +96,9 @@
computeHttpRequest = `${baseHttpRequest}${table}`; computeHttpRequest = `${baseHttpRequest}${table}`;
} }
return fetch(computeHttpRequest).then(response => response.json()); return fetch(computeHttpRequest).then(response => response.json());
},
navigateToPlaylists() {
route('/playlists');
} }
} }
</script> </script>

14
playlists.riot Normal file
View File

@ -0,0 +1,14 @@
<playlists>
<h1>Playlists Page</h1>
<p>This is the playlists page. It is currently empty.</p>
<script>
export default {
// Votre code de composant ici (si nécessaire)
}
</script>
<style>
/* Votre style ici (si nécessaire) */
</style>
</playlists>