Created
April 6, 2020 19:09
-
-
Save sroehrl/03e3c5de029d1278986103159719a0c9 to your computer and use it in GitHub Desktop.
helping out on reddit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<section id="courses-searched"> | |
<div class="course" v-for="(course, index) in courses.slice(0,10)" :key="index"> | |
<button | |
@click="course.show=!course.show"> | |
X | |
</button> | |
<div v-if="course.show" class="course"> | |
<div | |
id="course-name" | |
v-if="course.show"> | |
{{course.numsection.slice(0,-3)}} - {{course.name}} | |
</div> | |
<button v-for="appointment in course.schedule" @click="sectionSelected(course)">{{appointment.days}} - {{appointment.time}}</button> | |
</div> | |
</div> | |
</section> | |
</template> | |
<script> | |
import db from '../firebaseinit.js' | |
import {eventBus} from '../main' | |
export default { | |
data() { | |
return { | |
courses: [], | |
sectionsSelected: [] | |
} | |
}, | |
methods: { | |
sectionSelected(course) { | |
if (!(this.sectionsSelected.includes(course))) { | |
this.sectionsSelected.push(course); | |
eventBus.displaySection(this.sectionsSelected); | |
} else { | |
console.log(sectionsSelected) | |
} | |
} | |
}, | |
created() { | |
db.collection('spring20').get().then | |
(querySnapshot => { | |
let courses = {}; | |
querySnapshot.forEach(document => { | |
if (typeof courses[document.data().name] === 'undefined') { | |
courses[document.name] = { | |
'numsection': document.data().numsection, | |
'name': document.data().name, | |
schedule: [], | |
show: true | |
} | |
} else { | |
courses[document.name].schedule.push({ | |
days: document.data().days, | |
time: document.data().time | |
}) | |
} | |
}); | |
// convert to array | |
Object.keys(courses).forEach(course =>{ | |
this.courses.push(course) | |
}); | |
}) | |
} | |
}; | |
</script> | |
<style> | |
.course { | |
display: flex; | |
padding: 10px | |
} | |
#course-name { | |
padding-left: 10px; | |
padding-right: 10px; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment