Files
public-html2/parcoursup/app.riot
T

80 lines
1.7 KiB
Plaintext
Raw Normal View History

<app>
2026-03-31 17:54:23 +02:00
<h1>Mini projet Parcoursup</h1>
<p>Recherche de formations Parcoursup avec Riot</p>
<div if={ !state.selected }>
2026-03-31 17:55:55 +02:00
<search-bar onsearch={ launchSearch }></search-bar>
2026-03-31 17:54:23 +02:00
2026-03-31 17:55:55 +02:00
<result-list
results={ state.results }
hasSearched={ state.hasSearched }
loading={ state.loading }
ondetail={ showDetail }>
</result-list>
2026-03-31 17:54:23 +02:00
</div>
2026-03-31 17:54:23 +02:00
<div if={ state.selected }>
2026-03-31 17:55:55 +02:00
<detail-view
formation={ state.selected }
onback={ backToList }>
</detail-view>
</div>
<script>
2026-03-31 17:54:23 +02:00
import { fetchFormations } from './api.js'
import { createFormation } from './formation.js'
export default {
state: {
loading: false,
hasSearched: false,
results: [],
2026-03-31 17:54:23 +02:00
selected: null
},
2026-03-31 17:55:55 +02:00
async launchSearch(query) {
this.update({
loading: true,
hasSearched: true,
2026-03-31 17:54:23 +02:00
selected: null
})
try {
2026-03-31 17:55:55 +02:00
const data = await fetchFormations(query)
2026-03-31 17:54:23 +02:00
const formations = []
2026-03-31 17:54:23 +02:00
if (data.results) {
for (let i = 0; i < data.results.length; i++) {
2026-03-31 17:55:55 +02:00
const raw = data.results[i]
const formation = createFormation(raw)
formations.push(formation)
}
}
this.update({
results: formations,
loading: false
2026-03-31 17:54:23 +02:00
})
} catch (error) {
console.error(error)
this.update({
results: [],
loading: false
2026-03-31 17:54:23 +02:00
})
}
},
2026-03-31 17:54:23 +02:00
showDetail(index) {
this.update({
selected: this.state.results[index]
})
},
2026-03-31 17:54:23 +02:00
backToList() {
this.update({
selected: null
})
}
2026-03-31 17:54:23 +02:00
}
</script>
2026-03-31 17:54:23 +02:00
</app>