Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. <template>
  2. <DefaultLayout>
  3. <AppSection
  4. :class="{
  5. '!pb-0': !featured.length
  6. }"
  7. >
  8. <AppSectionHeader
  9. :title="subject.title"
  10. :subtitle="subject.description"
  11. />
  12.  
  13. <div
  14. class="flex flex-wrap -ml-4 -mr-4"
  15. v-if="featured.length"
  16. >
  17. <div
  18. class="w-full flex md:w-full lg:w-1/3 p-4"
  19. v-for="course in featured"
  20. :key="course.id"
  21. >
  22. <AppLibraryFeatureCard
  23. :course="course"
  24. />
  25. </div>
  26. </div>
  27. </AppSection>
  28.  
  29. <AppSection id="list">
  30. <AppListHeader :title="`All ${subject.title} content`" />
  31.  
  32. <AppPaginationMeta :pagination="pagination" />
  33.  
  34. <AppCourseList class="mb-6">
  35. <AppCourseListItem
  36. v-for="course in courses"
  37. :key="course.id"
  38. :course="course"
  39. />
  40. </AppCourseList>
  41.  
  42. <AppPagination
  43. :pagination="pagination"
  44. @change="paginationChanged"
  45. />
  46. </AppSection>
  47. </DefaultLayout>
  48. </template>
  49.  
  50. <script>
  51. import { mapGetters, mapActions } from 'vuex'
  52. import pluralize from 'pluralize'
  53. import VueScrollTo from 'vue-scrollto'
  54.  
  55. import DefaultLayout from '@/layouts/DefaultLayout'
  56. import AppSection from '@/components/elements/sections/AppSection'
  57. import AppSidebarSection from '@/components/elements/sections/AppSidebarSection'
  58. import AppSectionHeader from '@/components/elements/headers/AppSectionHeader'
  59. import AppLibraryFeatureCard from '@/components/elements/library/AppLibraryFeatureCard'
  60. import AppCourseList from '@/components/collections/courses/AppCourseList'
  61. import AppCourseListItem from '@/components/collections/courses/AppCourseListItem'
  62. import AppListHeader from '@/components/elements/headers/AppListHeader'
  63. import AppPagination from '@/components/elements/pagination/AppPagination'
  64. import AppPaginationMeta from '@/components/elements/pagination/AppPaginationMeta'
  65.  
  66. export default {
  67. head () {
  68. return {
  69. title: `${this.subject.title} - Subjects`
  70. }
  71. },
  72.  
  73. components: {
  74. DefaultLayout,
  75. AppSection,
  76. AppSectionHeader,
  77. AppLibraryFeatureCard,
  78. AppCourseList,
  79. AppCourseListItem,
  80. AppSidebarSection,
  81. AppListHeader,
  82. AppPagination,
  83. AppPaginationMeta
  84. },
  85.  
  86. data () {
  87. return {
  88. featured: []
  89. }
  90. },
  91.  
  92. computed: {
  93. ...mapGetters({
  94. subject: 'subject/subject',
  95. courses: 'subject/courses',
  96. pagination: 'subject/pagination'
  97. })
  98. },
  99.  
  100. methods: {
  101. pluralize,
  102.  
  103. ...mapActions({
  104. getCourses: 'subject/getCourses'
  105. }),
  106.  
  107. paginationChanged (page) {
  108. this.getCourses({
  109. slug: this.subject.slug,
  110. page
  111. })
  112.  
  113. VueScrollTo.scrollTo('#list')
  114. }
  115. },
  116.  
  117. async asyncData ({ app, store, params, error }) {
  118. try {
  119. await store.dispatch('subject/getSubject', params.slug)
  120.  
  121. await store.dispatch('subject/getCourses', {
  122. slug: params.slug
  123. })
  124.  
  125. const featured = await app.$axios.$get(`/courses?limit=3&subjects[]=${params.slug}&featured=true&featured_key=subject-index`)
  126.  
  127. return {
  128. featured: featured.data
  129. }
  130. } catch (e) {
  131. if (e.response) {
  132. error({ statusCode: e.response.status })
  133. }
  134. }
  135. }
  136. }
  137. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement