Skip to content

Commit edb2e76

Browse files
committed
refactor(partners): move partners fetch to plugin
1 parent 9d34881 commit edb2e76

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

components/organisms/sections/PartnersSection.vue

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Markdown use="category-title" unwrap="p" />
77
</h2>
88
</div>
9-
<div v-if="partners && partners.length" class="grid sm:grid-cols-2 lg:grid-cols-3 gap-6">
9+
<div v-if="partners" class="grid sm:grid-cols-2 lg:grid-cols-3 gap-6">
1010
<LogoCard v-for="partner in partners" :key="partner.id" :item="partner">
1111
<template #footer>
1212
<PartnerServices :services="partner.profile.services" class="text-sm mt-4" />
@@ -17,9 +17,9 @@
1717
</template>
1818

1919
<script lang="ts">
20-
import { defineComponent, useContext, ref, onMounted } from '@nuxtjs/composition-api'
20+
import { defineComponent, ref, onMounted } from '@nuxtjs/composition-api'
2121
import { scrollToHeading } from '@docus/theme/runtime'
22-
import { $fetch } from 'ohmyfetch'
22+
import { usePartners } from '~/plugins/partners'
2323
2424
export default defineComponent({
2525
props: {
@@ -33,17 +33,20 @@ export default defineComponent({
3333
}
3434
},
3535
setup(props) {
36-
const { $config } = useContext()
37-
const partners = ref(null)
36+
const { fetch: fetchPartners } = usePartners()
37+
const partners = ref([])
3838
39-
const fetch = async () => {
40-
const apiURL = $config.apiNuxtlabsURL || 'https://api.nuxtlabs.com'
39+
onMounted(async () => {
40+
if (window.location.hash) {
41+
const hash = window.location.hash.replace('#', '')
42+
43+
// do not remove setTimeout (wrong scroll pos)
44+
setTimeout(() => {
45+
scrollToHeading(hash, '--docs-scroll-margin-block')
46+
}, 300)
47+
}
4148
42-
const results = await $fetch(`${apiURL}/api/partners`, {
43-
params: {
44-
type: props.category
45-
}
46-
})
49+
const results = await fetchPartners(props.category)
4750
// mapping for LogoCard
4851
partners.value = results.map(partner => ({
4952
...partner,
@@ -55,19 +58,6 @@ export default defineComponent({
5558
title: partner.name,
5659
description: partner.profile.shortDescription
5760
}))
58-
}
59-
60-
onMounted(() => {
61-
fetch()
62-
63-
if (window.location.hash) {
64-
const hash = window.location.hash.replace('#', '')
65-
66-
// do not remove setTimeout (wrong scroll pos)
67-
setTimeout(() => {
68-
scrollToHeading(hash, '--docs-scroll-margin-block')
69-
}, 300)
70-
}
7161
})
7262
7363
return {

plugins/partners.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useContext } from '@nuxtjs/composition-api'
2+
import { $fetch } from 'ohmyfetch'
3+
4+
export function usePartners() {
5+
const { $config } = useContext()
6+
7+
const apiURL = $config.apiNuxtlabsURL || 'https://api.nuxtlabs.com'
8+
9+
const fetch = async type => {
10+
return await $fetch(`${apiURL}/api/partners`, {
11+
params: type ? { type } : {}
12+
})
13+
}
14+
15+
return {
16+
fetch
17+
}
18+
}

0 commit comments

Comments
 (0)