8888
8989<script setup>
9090import {get , isEmpty } from ' lodash'
91- import {onMounted , ref } from ' vue'
91+ import {computed , onMounted , ref } from ' vue'
92+ import {useRoute } from ' vue-router'
9293import AdmitDataWarning from ' @/components/admit/AdmitDataWarning.vue'
9394import CohortPageHeader from ' @/components/cohort/CohortPageHeader.vue'
9495import Date from ' @/components/util/Date.vue'
9596import Pagination from ' @/components/util/Pagination'
9697import {getCohortEvents } from ' @/api/cohort'
97- import {lastNameFirst , putFocusNextTick , scrollToTop , studentRoutePath } from ' @/lib/utils'
98+ import {lastNameFirst , putFocusNextTick , scrollToTop , studentRoutePath , toInt } from ' @/lib/utils'
9899import {useCohortStore } from ' @/stores/cohort-edit-session'
100+ import {loadCohort } from ' @/stores/cohort-edit-session/cohort-edit-session-utils'
99101import {useContextStore } from ' @/stores/context'
100102
103+ const cohortId = ref (0 )
101104const cohortStore = useCohortStore ()
102105const contextStore = useContextStore ()
103106
@@ -110,17 +113,36 @@ const totalEventsCount = ref(0)
110113
111114contextStore .loadingStart ()
112115
116+ const sortByKey = computed (() => cohortStore .domain === ' admitted_students' ? ' admitSortBy' : ' sortBy' )
117+
113118onMounted (() => {
114- goToPage (1 )
119+ init ().then (() => {
120+ goToPage (1 )
121+ })
115122})
116123
124+ const init = () => {
125+ return new Promise (resolve => {
126+ if (cohortStore && cohortStore .cohortId ) {
127+ cohortId .value = cohortStore .cohortId
128+ resolve ()
129+ } else {
130+ cohortId .value = toInt (get (useRoute (), ' params.id' ))
131+ const orderBy = get (currentUser .preferences , sortByKey .value )
132+ const termId = get (currentUser .preferences , ' termId' )
133+ cohortStore .resetSession ()
134+ loadCohort (cohortId .value , orderBy, termId).then (resolve)
135+ }
136+ })
137+ }
138+
117139const goToPage = page => {
118140 return new Promise (resolve => {
119141 currentPage .value = page
120142 offset .value = (page - 1 ) * itemsPerPage .value
121143 contextStore .loadingStart ()
122144 scrollToTop (10 )
123- getCohortEvents (cohortStore . cohortId , offset .value , itemsPerPage .value ).then (data => {
145+ getCohortEvents (cohortId . value , offset .value , itemsPerPage .value ).then (data => {
124146 totalEventsCount .value = data .count
125147 events .value = data .events
126148 contextStore .loadingComplete ()
0 commit comments