2026-03-18 12:45:44 +01:00
|
|
|
<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-18 12:45:44 +01:00
|
|
|
|
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>
|
2026-03-18 12:45:44 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
2026-03-31 17:54:23 +02:00
|
|
|
import { fetchFormations } from './api.js'
|
|
|
|
|
import { createFormation } from './formation.js'
|
|
|
|
|
|
2026-03-18 12:45:44 +01:00
|
|
|
export default {
|
|
|
|
|
state: {
|
|
|
|
|
loading: false,
|
|
|
|
|
hasSearched: false,
|
|
|
|
|
results: [],
|
2026-03-31 17:54:23 +02:00
|
|
|
selected: null
|
2026-03-18 14:17:03 +01:00
|
|
|
},
|
|
|
|
|
|
2026-03-31 17:55:55 +02:00
|
|
|
async launchSearch(query) {
|
2026-03-18 12:45:44 +01:00
|
|
|
this.update({
|
|
|
|
|
loading: true,
|
|
|
|
|
hasSearched: true,
|
2026-03-31 17:54:23 +02:00
|
|
|
selected: null
|
|
|
|
|
})
|
2026-03-18 12:45:44 +01:00
|
|
|
|
|
|
|
|
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-18 14:54:01 +01:00
|
|
|
|
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)
|
2026-03-18 12:45:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.update({
|
|
|
|
|
results: formations,
|
|
|
|
|
loading: false
|
2026-03-31 17:54:23 +02:00
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error)
|
2026-03-18 12:45:44 +01:00
|
|
|
this.update({
|
|
|
|
|
results: [],
|
|
|
|
|
loading: false
|
2026-03-31 17:54:23 +02:00
|
|
|
})
|
2026-03-18 12:45:44 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-03-31 17:54:23 +02:00
|
|
|
showDetail(index) {
|
|
|
|
|
this.update({
|
|
|
|
|
selected: this.state.results[index]
|
|
|
|
|
})
|
2026-03-18 14:54:01 +01:00
|
|
|
},
|
|
|
|
|
|
2026-03-31 17:54:23 +02:00
|
|
|
backToList() {
|
|
|
|
|
this.update({
|
|
|
|
|
selected: null
|
|
|
|
|
})
|
2026-03-18 12:45:44 +01:00
|
|
|
}
|
2026-03-31 17:54:23 +02:00
|
|
|
}
|
2026-03-18 12:45:44 +01:00
|
|
|
</script>
|
2026-03-31 17:54:23 +02:00
|
|
|
</app>
|