test route

This commit is contained in:
Matthis FAUVET 2024-06-29 01:31:50 +02:00
parent 0ce0fe7109
commit a0fe25b2a7
3 changed files with 1 additions and 67 deletions

1
.idea/vcs.xml generated
View File

@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -39,10 +39,6 @@
</div>
<script>
riot.compile().then(() => {
riot.mount('playlist-form');
})
export default {
async onBeforeMount(props) {
let data = await props.items;

View File

@ -1,63 +0,0 @@
<playlist-form>
<form onsubmit={handleSubmit}>
<label for="playlist-name">Nom de la playlist</label>
<input type="text" id="playlist-name" name="playlist-name"/>
<button>Créer la playlist</button>
</form>
<script>
this.handleSubmit = async (event) => {
event.preventDefault();
const formData = new FormData(event.target);
const playlistName = formData.get('playlist-name');
try {
const response = await fetch('https://dwarves.iut-fbleau.fr/~fauvet/api/playlists', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({name: playlistName})
});
if(!response.ok) {
throw new Error('Erreur lors de la création de la playlist');
}
event.target.reset();
alert('Playlist créée avec succès !');
} catch(error) {
console.error('Erreur : ', error);
alert('Une erreur est survenue lors de la création de la playlist');
}
}
</script>
<style>
form {
display: flex;
flex-direction: column;
max-width: 300px;
margin: 20px auto;
z-index: 15;
}
label, input {
margin-bottom: 10px;
}
button {
padding: 10px;
background-color: #6EE7B7;
border: none;
color: white;
cursor: pointer;
}
button:hover {
background-color: #059669;
}
</style>
</playlist-form>