@worksafevictoria/wcl7.5 1.1.0-beta.92 → 1.1.0-beta.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worksafevictoria/wcl7.5",
3
- "version": "1.1.0-beta.92",
3
+ "version": "1.1.0-beta.93",
4
4
  "main": "src/index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -2,43 +2,66 @@ import HomepageHeader from './index.vue'
2
2
 
3
3
  const header = {
4
4
  title: 'This is sentence 1. This is sentence 2.',
5
- description: 'description text'
5
+ description: 'description text',
6
6
  }
7
7
 
8
- const fetchMenu = () =>
9
- Promise.resolve([
10
- {
11
- title: 'Report an incident',
12
- relative: '/report-incident'
13
- },
14
- {
15
- title: 'Report a case of COVID-19',
16
- relative: '/report-confirmed-positive-case-covid-19'
17
- },
18
- {
19
- title: 'Make a claim',
20
- relative: '/before-claim'
21
- },
22
- {
23
- title: 'Apply for a licence',
24
- relative: '/apply-for-licence'
25
- },
26
- {
27
- title: 'Pay or renew your insurance',
28
- relative: '/pay-or-renew-your-workcover-insurance-premium'
29
- }
30
- ])
8
+ // This is generated server side with useAsyncData
9
+ // const fetchMenu = () =>
10
+ // Promise.resolve([
11
+ // {
12
+ // title: 'Report an incident',
13
+ // relative: '/report-incident'
14
+ // },
15
+ // {
16
+ // title: 'Report a case of COVID-19',
17
+ // relative: '/report-confirmed-positive-case-covid-19'
18
+ // },
19
+ // {
20
+ // title: 'Make a claim',
21
+ // relative: '/before-claim'
22
+ // },
23
+ // {
24
+ // title: 'Apply for a licence',
25
+ // relative: '/apply-for-licence'
26
+ // },
27
+ // {
28
+ // title: 'Pay or renew your insurance',
29
+ // relative: '/pay-or-renew-your-workcover-insurance-premium'
30
+ // }
31
+ // ])
32
+ const headerLinks = [
33
+ {
34
+ text: 'Report an incident',
35
+ path: '/report-incident',
36
+ },
37
+ {
38
+ text: 'Report a case of COVID-19',
39
+ path: '/report-confirmed-positive-case-covid-19',
40
+ },
41
+ {
42
+ text: 'Make a claim',
43
+ path: '/before-claim',
44
+ },
45
+ {
46
+ text: 'Apply for a licence',
47
+ path: '/apply-for-licence',
48
+ },
49
+ {
50
+ text: 'Pay or renew your insurance',
51
+ path: '/pay-or-renew-your-workcover-insurance-premium',
52
+ },
53
+ ]
31
54
 
32
55
  const contentParser = () => {
33
56
  return Promise.resolve({
34
57
  results: [
35
58
  {
36
59
  title: 'Content title 1',
37
- description: 'Content description 2'
38
- }
60
+ description: 'Content description 2',
61
+ },
39
62
  ],
40
63
  offset: 0,
41
- numFound: 1000
64
+ numFound: 1000,
42
65
  })
43
66
  }
44
67
 
@@ -48,31 +71,32 @@ export default {
48
71
  argTypes: {
49
72
  fetchMenu: {
50
73
  control: 'function',
51
- table: { disable: true }
74
+ table: { disable: true },
52
75
  },
53
76
  contentParser: {
54
77
  control: 'function',
55
- table: { disable: true }
56
- }
78
+ table: { disable: true },
79
+ },
57
80
  },
58
81
  args: {
59
82
  heroHeader: header,
60
- fetchMenu: fetchMenu,
61
- contentParser: contentParser
62
- }
83
+ // fetchMenu: fetchMenu,
84
+ contentParser: contentParser,
85
+ headerLinks: headerLinks,
86
+ },
63
87
  }
64
88
 
65
89
  const DefaultHH = (args) => ({
66
90
  components: { HomepageHeader },
67
91
  setup() {
68
- return { args };
92
+ return { args }
69
93
  },
70
94
  mounted() {
71
95
  setTimeout(() => {
72
96
  this.$refs.hh.renderMenu()
73
97
  })
74
98
  },
75
- template: '<homepage-header v-bind="args" ref="hh" />'
99
+ template: '<homepage-header v-bind="args" ref="hh" />',
76
100
  })
77
101
 
78
- export const Default = DefaultHH.bind({})
102
+ export const Default = DefaultHH.bind({})
@@ -30,7 +30,7 @@
30
30
  <template v-slot:side>
31
31
  <div>
32
32
  <cta-button
33
- v-for="(link, i) in links"
33
+ v-for="(link, i) in headerLinks"
34
34
  :key="i"
35
35
  class="iebtn"
36
36
  :url="link.path"
@@ -51,45 +51,34 @@
51
51
  </template>
52
52
  </hero-header>
53
53
  </template>
54
- <script setup>
54
+ <script>
55
55
  import Search from './../../SubComponents/Search/index.vue'
56
56
  import CtaButton from './../../SubComponents/CtaButton/index.vue'
57
57
  import HeroHeader from './../../Global/HeroHeader/index.vue'
58
58
  import earthIcon from './../../../assets/icons/earth.svg?url'
59
59
 
60
- const props = defineProps({
61
- contentParser: {
62
- type: Function,
63
- required: true,
60
+ export default {
61
+ name: 'HomepageHeader',
62
+ components: {
63
+ Search,
64
+ CtaButton,
65
+ HeroHeader,
64
66
  },
65
- heroHeader: {
66
- type: Object,
67
- required: true,
67
+ props: {
68
+ contentParser: {
69
+ type: Function,
70
+ required: true,
71
+ },
72
+ heroHeader: {
73
+ type: Object,
74
+ required: true,
75
+ },
76
+ headerLinks: { type: Array, required: true },
68
77
  },
69
- fetchMenu: {
70
- type: Function,
71
- required: true,
72
- },
73
- })
74
-
75
- const links = ref([])
76
78
 
77
- await useAsyncData('fetchData', async () => {
78
- try {
79
- await renderMenu()
80
- } catch (err) {
81
- console.log('🚀 ~ err:', err)
82
- }
83
- })
84
-
85
- async function renderMenu() {
86
- const menu = await props.fetchMenu()
87
- links.value = (Array.isArray(menu) ? menu : []).map((item) => {
88
- return {
89
- text: item.title,
90
- path: item.relative || item.absolute,
91
- }
92
- })
79
+ data: () => ({
80
+ earthIcon,
81
+ }),
93
82
  }
94
83
  </script>
95
84
  <style lang="scss" scoped>
@@ -38,226 +38,250 @@
38
38
  </card-group>
39
39
  </template>
40
40
 
41
- <script setup>
41
+ <script>
42
42
  import CardGroup from '../../SubComponents/CardGroup/index.vue'
43
43
  import DirectoryFilters from '../../Global/DirectoryFilters/index.vue'
44
44
  import Switcher from './switcher.vue'
45
45
 
46
- const nuxtApp = useNuxtApp()
47
-
48
- const hasMorePages = ref(false)
49
- const displayedCards = ref([])
50
- const loading = ref(true)
51
- const bundleCache = ref({})
52
- const displayLimit = ref(0)
53
- const allCards = ref(undefined)
54
- const filters = ref({
55
- taxonomies: [],
56
- selected: {},
57
- availableBundles: [],
58
- })
59
- const props = defineProps({
60
- background: {
61
- type: String,
62
- default: 'grey',
63
- },
64
- title: {
65
- type: String,
66
- default: '',
67
- },
68
- titleTag: {
69
- type: String,
70
- default: 'h2',
71
- },
72
- bundle: {
73
- type: Array,
74
- default: () => [''],
75
- },
76
- columns: {
77
- type: Number,
78
- default: 0,
79
- },
80
- initialDisplyLimit: {
81
- type: Number,
82
- default: 0,
83
- },
84
- fetchContent: {
85
- type: Function,
86
- required: true,
87
- },
88
- fetchFilters: {
89
- type: Function,
90
- required: false,
91
- default: null,
92
- },
93
- enableBundleFilter: {
94
- type: Boolean,
46
+ export default {
47
+ name: 'BrowseContent',
48
+ components: {
49
+ CardGroup,
50
+ DirectoryFilters,
51
+ Switcher,
95
52
  },
96
- getBundleAlias: {
97
- type: Function,
98
- required: false,
99
- default: null,
100
- },
101
- showMore: {
102
- type: Boolean,
53
+ props: {
54
+ background: {
55
+ type: String,
56
+ default: 'grey',
57
+ },
58
+ title: {
59
+ type: String,
60
+ default: '',
61
+ },
62
+ titleTag: {
63
+ type: String,
64
+ default: 'h2',
65
+ },
66
+ bundle: {
67
+ type: Array,
68
+ default: () => [''],
69
+ },
70
+ columns: {
71
+ type: Number,
72
+ default: 0,
73
+ },
74
+ initialDisplyLimit: {
75
+ type: Number,
76
+ default: 0,
77
+ },
78
+ fetchContent: {
79
+ type: Function,
80
+ required: true,
81
+ },
82
+ fetchFilters: {
83
+ type: Function,
84
+ required: false,
85
+ default: null,
86
+ },
87
+ enableBundleFilter: {
88
+ type: Boolean,
89
+ },
90
+ getBundleAlias: {
91
+ type: Function,
92
+ required: false,
93
+ default: null,
94
+ },
95
+ showMore: {
96
+ type: Boolean,
97
+ },
98
+ type: {
99
+ type: String,
100
+ required: true,
101
+ },
103
102
  },
104
- type: {
105
- type: String,
106
- required: true,
103
+ // Temp use of mounted to replace fetch
104
+ async mounted() {
105
+ if (this.displayedCards.length === 0) {
106
+ await this.loadFiltersAndContent()
107
+ }
107
108
  },
108
- })
109
-
110
- await useAsyncData('fetchData', async () => {
111
- try {
112
- await Promise.all([
113
- props.fetchFilters ? loadFilters() : Promise.resolve(),
114
- loadMoreCards(true),
115
- ])
116
- } catch (err) {
117
- console.log('🚀 ~ err:', err)
118
- }
119
- })
120
-
121
- function initial() {
122
- allCards.value = {
123
- total: 0,
124
- cards: [],
125
- }
126
- displayLimit.value = 0
127
- hasMorePages.value = false
128
- displayedCards.value = []
129
- bundleCache.value = {}
130
- }
131
- async function fetchCards(currentDisplayedCards, allCards, addMoreBy, bundles) {
132
- const shouldMakeNewFetchCall =
133
- currentDisplayedCards.length + addMoreBy > allCards.cards.length
134
- if (shouldMakeNewFetchCall) {
135
- const cardBundles = await Promise.all(
136
- bundles.map((bundle, index) => getBundle(bundle, addMoreBy, index)),
137
- )
138
- allCards = getShuffledCards(cardBundles)
139
-
140
- if (
141
- props.type === 'paragraph--cards_group_latest' ||
142
- props.type === 'paragraph--browse_content'
143
- ) {
144
- allCards.cards = sortByDate(allCards.cards)
109
+ // TODO useAsyncData <script setup>
110
+ // async fetch() {
111
+ // if (this.displayedCards.length === 0) {
112
+ // await this.loadFiltersAndContent()
113
+ // }
114
+ // },
115
+ data() {
116
+ return {
117
+ hasMorePages: false,
118
+ displayedCards: [],
119
+ loading: true,
120
+ bundleCache: {},
121
+ displayLimit: 0,
122
+ allCards: undefined,
123
+ filters: {
124
+ taxonomies: [],
125
+ selected: {},
126
+ availableBundles: [],
127
+ },
145
128
  }
146
- }
147
- return allCards
148
- }
129
+ },
130
+ fetchKey: 'ws-browscontent',
131
+ methods: {
132
+ async loadFiltersAndContent() {
133
+ await Promise.all([
134
+ this.fetchFilters ? this.loadFilters() : Promise.resolve(),
135
+ this.loadMoreCards(true),
136
+ ])
137
+ },
138
+ init() {
139
+ this.allCards = {
140
+ total: 0,
141
+ cards: [],
142
+ }
143
+ this.displayLimit = 0
144
+ this.hasMorePages = false
145
+ this.displayedCards = []
146
+ this.bundleCache = {}
147
+ },
148
+ async fetchCards(currentDisplayedCards, allCards, addMoreBy, bundles) {
149
+ const shouldMakeNewFetchCall =
150
+ currentDisplayedCards.length + addMoreBy > allCards.cards.length
151
+ if (shouldMakeNewFetchCall) {
152
+ const cardBundles = await Promise.all(
153
+ bundles.map((bundle, index) =>
154
+ this.getBundle(bundle, addMoreBy, index),
155
+ ),
156
+ )
157
+ allCards = this.getShuffledCards(cardBundles)
149
158
 
150
- async function loadMoreCards(init) {
151
- const attrs = {
152
- group: nuxtApp.$pageStore?.content?.title,
153
- }
154
- if (nuxtApp.$gtm && !init) {
155
- nuxtApp.$gtm.push({ event: 'custom.interaction.showmore.click', ...attrs })
156
- }
157
- if (init) {
158
- initial()
159
- }
160
- loading.value = true
161
- const addMoreBy = props.initialDisplyLimit
162
- displayLimit.value += addMoreBy
163
- const bundles =
164
- filters.value.availableBundles.length > 0
165
- ? filters.value.availableBundles
166
- : props.bundle
167
- allCards.value = await fetchCards(
168
- displayedCards.value,
169
- allCards.value,
170
- addMoreBy,
171
- bundles,
172
- )
173
- hasMorePages.value = allCards.value.total > allCards.value.cards.length
174
- displayedCards.value = allCards.value.cards.slice(0, displayLimit.value)
175
- loading.value = false
176
- }
177
- async function getBundle(bundle, addMoreBy, index) {
178
- let start
179
- const rows = addMoreBy
180
- const cache = (bundleCache.value[bundle] = bundleCache.value[bundle] || {
181
- response: {
182
- results: [],
183
- numFound: 0,
159
+ if (
160
+ this.type === 'paragraph--cards_group_latest' ||
161
+ this.type === 'paragraph--browse_content'
162
+ ) {
163
+ allCards.cards = this.sortByDate(allCards.cards)
164
+ }
165
+ }
166
+ return allCards
184
167
  },
185
- qs: {
186
- start,
168
+ async loadMoreCards(init) {
169
+ const attrs = {
170
+ group: this.$pageStore?.content?.title,
171
+ }
172
+ if (this.$gtm && !init) {
173
+ this.$gtm.push({ event: 'custom.interaction.showmore.click', ...attrs })
174
+ }
175
+ if (init) {
176
+ this.init()
177
+ }
178
+ this.loading = true
179
+ const addMoreBy = this.initialDisplyLimit
180
+ this.displayLimit += addMoreBy
181
+ const bundles =
182
+ this.filters.availableBundles.length > 0
183
+ ? this.filters.availableBundles
184
+ : this.bundle
185
+ this.allCards = await this.fetchCards(
186
+ this.displayedCards,
187
+ this.allCards,
188
+ addMoreBy,
189
+ bundles,
190
+ )
191
+ this.hasMorePages = this.allCards.total > this.allCards.cards.length
192
+ this.displayedCards = this.allCards.cards.slice(0, this.displayLimit)
193
+ this.loading = false
187
194
  },
188
- })
189
- if (cache.qs.start === undefined) {
190
- start = 0
191
- } else if (cache.response.numFound > cache.response.results.length) {
192
- start = cache.response.results.length
193
- } else {
194
- return Promise.resolve(cache.response)
195
- }
196
- const qs = {
197
- bundle,
198
- rows,
199
- start,
200
- }
201
- let response = await props.fetchContent(qs, filters.value.selected)
202
- cache.qs.start = qs.start
203
- cache.response.numFound = response.numFound
204
- cache.response.results.push(...response.results)
205
- return cache.response
206
- }
207
- function getShuffledCards(cardBundles) {
208
- const shuffled = []
209
- const bundleWithMostCards = cardBundles.reduce(
210
- (a, b) => (a.results.length > b.results.length ? a : b),
211
- { results: [] },
212
- ).results.length
195
+ getBundle(bundle, addMoreBy, index) {
196
+ let start
197
+ const rows = addMoreBy
198
+ const cache = (this.bundleCache[bundle] = this.bundleCache[bundle] || {
199
+ response: {
200
+ results: [],
201
+ numFound: 0,
202
+ },
203
+ qs: {
204
+ start,
205
+ },
206
+ })
213
207
 
214
- for (let i = 0; i < bundleWithMostCards; i++) {
215
- cardBundles.forEach((bundle) => {
216
- if (bundle.results[i]) {
217
- shuffled.push(bundle.results[i])
208
+ if (cache.qs.start === undefined) {
209
+ start = 0
210
+ } else if (cache.response.numFound > cache.response.results.length) {
211
+ start = cache.response.results.length
212
+ } else {
213
+ return Promise.resolve(cache.response)
218
214
  }
219
- })
220
- }
221
215
 
222
- const total = cardBundles.reduce((acc, bundle) => {
223
- return acc + bundle.numFound
224
- }, 0)
216
+ const qs = {
217
+ bundle,
218
+ rows,
219
+ start,
220
+ }
221
+ return this.fetchContent(qs, this.filters.selected, index).then(
222
+ (response) => {
223
+ cache.qs.start = qs.start
224
+ cache.response.numFound = response.numFound
225
+ cache.response.results.push(...response.results)
226
+ return cache.response
227
+ },
228
+ )
229
+ },
230
+ getShuffledCards(cardBundles) {
231
+ const shuffled = []
232
+ const bundleWithMostCards = cardBundles.reduce(
233
+ (a, b) => (a.results.length > b.results.length ? a : b),
234
+ { results: [] },
235
+ ).results.length
236
+
237
+ for (let i = 0; i < bundleWithMostCards; i++) {
238
+ cardBundles.forEach((bundle) => {
239
+ if (bundle.results[i]) {
240
+ shuffled.push(bundle.results[i])
241
+ }
242
+ })
243
+ }
225
244
 
226
- return { cards: shuffled, total }
227
- }
228
- function loadFilters() {
229
- return props.fetchFilters().then((taxonomies) => {
230
- filters.value.taxonomies = taxonomies
245
+ const total = cardBundles.reduce((acc, bundle) => {
246
+ return acc + bundle.numFound
247
+ }, 0)
231
248
 
232
- return Promise.resolve(taxonomies)
233
- })
234
- }
235
- const onFilter = (fltrs) => {
236
- bundleCache.value = {}
237
- Object.keys(fltrs).forEach((filter) => {
238
- filters.values.selected[filter] = fltrs[filter].map((obj) => obj.tid)
239
- })
240
- loadMoreCards(true)
241
- }
242
- const onSwitcher = (switchToBundle) => {
243
- filters.value.selected = {}
244
- filters.value.availableBundles.length = 0
245
- if (switchToBundle) {
246
- filters.value.availableBundles.push(switchToBundle)
247
- }
248
- loadMoreCards(true)
249
- }
250
- const reset = async () => {
251
- bundleCache.value = {}
252
- filters.value.selected = {}
253
- filters.value.availableBundles.length = 0
254
- await loadMoreCards(true)
255
- }
256
- function sortByDate(cards) {
257
- const sorted = cards.sort((a, b) => {
258
- return new Date(b.dateSort) - new Date(a.dateSort)
259
- })
260
- return sorted
249
+ return { cards: shuffled, total }
250
+ },
251
+ loadFilters() {
252
+ return this.fetchFilters().then((taxonomies) => {
253
+ this.filters.taxonomies = taxonomies
254
+ return Promise.resolve(taxonomies)
255
+ })
256
+ },
257
+ onFilter(filters) {
258
+ this.bundleCache = {}
259
+ Object.keys(filters).forEach((filter) => {
260
+ this.filters.selected[filter] = filters[filter].map((obj) => obj.tid)
261
+ })
262
+ this.loadMoreCards(true)
263
+ },
264
+ onSwitcher(switchToBundle) {
265
+ this.filters.selected = {}
266
+ this.filters.availableBundles.length = 0
267
+ if (switchToBundle) {
268
+ this.filters.availableBundles.push(switchToBundle)
269
+ }
270
+ this.loadMoreCards(true)
271
+ },
272
+ async reset() {
273
+ this.bundleCache = {}
274
+ this.filters.selected = {}
275
+ this.filters.availableBundles.length = 0
276
+ await this.loadMoreCards(true)
277
+ },
278
+ sortByDate(cards) {
279
+ const sorted = cards.sort((a, b) => {
280
+ return new Date(b.dateSort) - new Date(a.dateSort)
281
+ })
282
+ return sorted
283
+ },
284
+ },
261
285
  }
262
286
  </script>
263
287
  <style lang="scss" scoped>
@@ -0,0 +1,284 @@
1
+ <template>
2
+ <card-group
3
+ :title="title"
4
+ :title-tag="titleTag"
5
+ :background="background"
6
+ :cards="displayedCards"
7
+ :loading="loading"
8
+ :columns="columns"
9
+ :show-load-more="showMore && hasMorePages"
10
+ :class="`wcl-browse-content card_group__card--col-${columns}`"
11
+ :card-browse-content="true"
12
+ @loadMore="() => loadMoreCards(false)"
13
+ >
14
+ <template
15
+ v-if="enableBundleFilter && bundle.length > 1"
16
+ v-slot:cardGroupFilter
17
+ >
18
+ <switcher
19
+ v-if="enableBundleFilter"
20
+ :options="bundle"
21
+ class="wcl-browse-content__switcher"
22
+ :get-option-alias="getBundleAlias"
23
+ @switched="onSwitcher"
24
+ @reset="onSwitcher"
25
+ />
26
+ </template>
27
+
28
+ <template v-if="filters.taxonomies.length > 0" v-slot:cardGroupPreContent>
29
+ <directory-filters
30
+ class="wcl-browse-content__filter"
31
+ :filters="filters"
32
+ :results="allCards.total"
33
+ :is-filtering="loading"
34
+ @onFilter="onFilter"
35
+ @onReset="reset"
36
+ />
37
+ </template>
38
+ </card-group>
39
+ </template>
40
+
41
+ <script setup>
42
+ import CardGroup from '../../SubComponents/CardGroup/index.vue'
43
+ import DirectoryFilters from '../../Global/DirectoryFilters/index.vue'
44
+ import Switcher from './switcher.vue'
45
+
46
+ const nuxtApp = useNuxtApp()
47
+
48
+ const hasMorePages = ref(false)
49
+ const displayedCards = ref([])
50
+ const loading = ref(true)
51
+ const bundleCache = ref({})
52
+ const displayLimit = ref(0)
53
+ const allCards = ref(undefined)
54
+ const filters = ref({
55
+ taxonomies: [],
56
+ selected: {},
57
+ availableBundles: [],
58
+ })
59
+ const props = defineProps({
60
+ background: {
61
+ type: String,
62
+ default: 'grey',
63
+ },
64
+ title: {
65
+ type: String,
66
+ default: '',
67
+ },
68
+ titleTag: {
69
+ type: String,
70
+ default: 'h2',
71
+ },
72
+ bundle: {
73
+ type: Array,
74
+ default: () => [''],
75
+ },
76
+ columns: {
77
+ type: Number,
78
+ default: 0,
79
+ },
80
+ initialDisplyLimit: {
81
+ type: Number,
82
+ default: 0,
83
+ },
84
+ fetchContent: {
85
+ type: Function,
86
+ required: true,
87
+ },
88
+ fetchFilters: {
89
+ type: Function,
90
+ required: false,
91
+ default: null,
92
+ },
93
+ enableBundleFilter: {
94
+ type: Boolean,
95
+ },
96
+ getBundleAlias: {
97
+ type: Function,
98
+ required: false,
99
+ default: null,
100
+ },
101
+ showMore: {
102
+ type: Boolean,
103
+ },
104
+ type: {
105
+ type: String,
106
+ required: true,
107
+ },
108
+ })
109
+
110
+ await useAsyncData('fetchData', async () => {
111
+ try {
112
+ await Promise.all([
113
+ props.fetchFilters ? loadFilters() : Promise.resolve(),
114
+ loadMoreCards(true),
115
+ ])
116
+ } catch (err) {
117
+ console.log('🚀 ~ err:', err)
118
+ }
119
+ })
120
+
121
+ function initial() {
122
+ allCards.value = {
123
+ total: 0,
124
+ cards: [],
125
+ }
126
+ displayLimit.value = 0
127
+ hasMorePages.value = false
128
+ displayedCards.value = []
129
+ bundleCache.value = {}
130
+ }
131
+ async function fetchCards(currentDisplayedCards, allCards, addMoreBy, bundles) {
132
+ const shouldMakeNewFetchCall =
133
+ currentDisplayedCards.length + addMoreBy > allCards.cards.length
134
+ if (shouldMakeNewFetchCall) {
135
+ const cardBundles = await Promise.all(
136
+ bundles.map((bundle, index) => getBundle(bundle, addMoreBy, index)),
137
+ )
138
+ allCards = getShuffledCards(cardBundles)
139
+
140
+ if (
141
+ props.type === 'paragraph--cards_group_latest' ||
142
+ props.type === 'paragraph--browse_content'
143
+ ) {
144
+ allCards.cards = sortByDate(allCards.cards)
145
+ }
146
+ }
147
+ return allCards
148
+ }
149
+
150
+ async function loadMoreCards(init) {
151
+ const attrs = {
152
+ group: nuxtApp.$pageStore?.content?.title,
153
+ }
154
+ if (nuxtApp.$gtm && !init) {
155
+ nuxtApp.$gtm.push({ event: 'custom.interaction.showmore.click', ...attrs })
156
+ }
157
+ if (init) {
158
+ initial()
159
+ }
160
+ loading.value = true
161
+ const addMoreBy = props.initialDisplyLimit
162
+ displayLimit.value += addMoreBy
163
+ const bundles =
164
+ filters.value.availableBundles.length > 0
165
+ ? filters.value.availableBundles
166
+ : props.bundle
167
+ allCards.value = await fetchCards(
168
+ displayedCards.value,
169
+ allCards.value,
170
+ addMoreBy,
171
+ bundles,
172
+ )
173
+ hasMorePages.value = allCards.value.total > allCards.value.cards.length
174
+ displayedCards.value = allCards.value.cards.slice(0, displayLimit.value)
175
+ loading.value = false
176
+ }
177
+ async function getBundle(bundle, addMoreBy, index) {
178
+ let start
179
+ const rows = addMoreBy
180
+ const cache = (bundleCache.value[bundle] = bundleCache.value[bundle] || {
181
+ response: {
182
+ results: [],
183
+ numFound: 0,
184
+ },
185
+ qs: {
186
+ start,
187
+ },
188
+ })
189
+ if (cache.qs.start === undefined) {
190
+ start = 0
191
+ } else if (cache.response.numFound > cache.response.results.length) {
192
+ start = cache.response.results.length
193
+ } else {
194
+ return Promise.resolve(cache.response)
195
+ }
196
+ const qs = {
197
+ bundle,
198
+ rows,
199
+ start,
200
+ }
201
+ let response = await props.fetchContent(qs, filters.value.selected)
202
+ cache.qs.start = qs.start
203
+ cache.response.numFound = response.numFound
204
+ cache.response.results.push(...response.results)
205
+ return cache.response
206
+ }
207
+ function getShuffledCards(cardBundles) {
208
+ const shuffled = []
209
+ const bundleWithMostCards = cardBundles.reduce(
210
+ (a, b) => (a.results.length > b.results.length ? a : b),
211
+ { results: [] },
212
+ ).results.length
213
+
214
+ for (let i = 0; i < bundleWithMostCards; i++) {
215
+ cardBundles.forEach((bundle) => {
216
+ if (bundle.results[i]) {
217
+ shuffled.push(bundle.results[i])
218
+ }
219
+ })
220
+ }
221
+
222
+ const total = cardBundles.reduce((acc, bundle) => {
223
+ return acc + bundle.numFound
224
+ }, 0)
225
+
226
+ return { cards: shuffled, total }
227
+ }
228
+ function loadFilters() {
229
+ return props.fetchFilters().then((taxonomies) => {
230
+ filters.value.taxonomies = taxonomies
231
+
232
+ return Promise.resolve(taxonomies)
233
+ })
234
+ }
235
+ const onFilter = (fltrs) => {
236
+ bundleCache.value = {}
237
+ Object.keys(fltrs).forEach((filter) => {
238
+ filters.values.selected[filter] = fltrs[filter].map((obj) => obj.tid)
239
+ })
240
+ loadMoreCards(true)
241
+ }
242
+ const onSwitcher = (switchToBundle) => {
243
+ filters.value.selected = {}
244
+ filters.value.availableBundles.length = 0
245
+ if (switchToBundle) {
246
+ filters.value.availableBundles.push(switchToBundle)
247
+ }
248
+ loadMoreCards(true)
249
+ }
250
+ const reset = async () => {
251
+ bundleCache.value = {}
252
+ filters.value.selected = {}
253
+ filters.value.availableBundles.length = 0
254
+ await loadMoreCards(true)
255
+ }
256
+ function sortByDate(cards) {
257
+ const sorted = cards.sort((a, b) => {
258
+ return new Date(b.dateSort) - new Date(a.dateSort)
259
+ })
260
+ return sorted
261
+ }
262
+ </script>
263
+ <style lang="scss" scoped>
264
+ .wcl-browse-content {
265
+ &__filter {
266
+ align-items: flex-end;
267
+ place-content: flex-end;
268
+ }
269
+
270
+ &.card_group__card--col-4 {
271
+ :deep(.card-grid__column .card-grid-item__description) {
272
+ display: none;
273
+ }
274
+ }
275
+
276
+ :deep(.card_group__card--blue .card_item__desc p) {
277
+ margin-top: 12px;
278
+ }
279
+
280
+ :deep(.card_group__card--red .card_item__desc p) {
281
+ margin-top: 12px;
282
+ }
283
+ }
284
+ </style>
@@ -18,7 +18,7 @@ export class FileFormElement extends BaseFormElement {
18
18
  const blob = new Blob([byteArray], { type: 'text/plain' })
19
19
 
20
20
  return axios.post(
21
- `https://content-dev-v2.api.worksafe.vic.gov.au/webform_rest/${this.webformElement['#webform']}/upload/file`,
21
+ `https://content-dev-v2.api.worksafe.vic.gov.au/webform_rest/${this.webformElement['#webform']}/upload/${this.webformElement['#webform_key']}`,
22
22
  blob,
23
23
  {
24
24
  headers: {
@@ -43,8 +43,6 @@ export class FileFormElement extends BaseFormElement {
43
43
  value: '',
44
44
  },
45
45
  ],
46
- key: 'file',
47
- type: 'file',
48
46
  input: true,
49
47
  fileKey: `files[${this.webformElement['#name']}]`,
50
48
  }
package/src/index.js CHANGED
@@ -25,7 +25,7 @@ import RichText from './components/Paragraphs/RichText/index.vue'
25
25
  import TextMedia from './components/Paragraphs/TextMedia/index.vue'
26
26
  import Accordion from './components/Paragraphs/Accordion/index.vue'
27
27
  import TabbedCards from './components/Paragraphs/TabbedCards/index.vue'
28
- // import BrowseContent from './components/Paragraphs/BrowseContent/index.vue'
28
+ import BrowseContent from './components/Paragraphs/BrowseContent/index.vue'
29
29
  import TaskFinder from './components/Paragraphs/TaskFinder/index.vue'
30
30
  import ListGroup from './components/Paragraphs/ListGroup/index.vue'
31
31
  import ScrollSpy from './components/Paragraphs/ScrollSpy/index.vue'
@@ -56,6 +56,9 @@ import Search from './components/SubComponents/Search/index.vue'
56
56
  import VideoThumbnail from './components/SubComponents/VideoThumbnail/index.vue'
57
57
  import ResourceGroup from './components/SubComponents/ResourceGroup/index.vue'
58
58
 
59
+ // Temp Components for testing
60
+ import BrowseContent2 from './components/Paragraphs/BrowseContent/setup.vue'
61
+
59
62
  // Export Global Components
60
63
  export {
61
64
  Container,
@@ -89,7 +92,7 @@ export {
89
92
  TextMedia,
90
93
  Accordion,
91
94
  TabbedCards,
92
- // BrowseContent, moved to FE
95
+ BrowseContent,
93
96
  ListGroup,
94
97
  ScrollSpy,
95
98
  Directory,
@@ -128,3 +131,6 @@ export {
128
131
  DirectoryFilters,
129
132
  Switcher,
130
133
  }
134
+
135
+ // Temp Components for testing
136
+ export { BrowseContent2 }