多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB

2 months ago
import axios from 'axios'
import type { ProductFeedItem } from '../lib/types'
2 months ago
const axiosInstance = axios.create({
2 months ago
baseURL: 'https://nocodb.com/api/v1',
2 months ago
headers: {
'Content-Type': 'application/json',
},
})
export const useProductFeed = createSharedComposable(() => {
const activeTab = ref('recents')
const youtubeFeed = ref<ProductFeedItem[]>([])
2 months ago
const githubFeed = ref<ProductFeedItem[]>([])
2 months ago
const socialFeed = ref<ProductFeedItem[]>([])
2 months ago
const loadFeed = async ({ loadMore, type }: { loadMore: boolean; type: 'youtube' | 'github' | 'all' | 'twitter' }) => {
2 months ago
try {
let page = 1
if (loadMore) {
switch (type) {
case 'youtube':
page = Math.ceil(youtubeFeed.value.length / 10) + 1
break
case 'github':
page = Math.ceil(githubFeed.value.length / 10) + 1
break
case 'all':
page = Math.ceil(socialFeed.value.length / 10) + 1
break
}
}
const response = await axiosInstance.get<ProductFeedItem[]>('/social/feed', {
2 months ago
params: {
per_page: 10,
page,
type,
},
})
return response.data
} catch (error) {
console.error(error)
return []
}
2 months ago
}
return {
activeTab,
youtubeFeed,
githubFeed,
socialFeed,
loadFeed,
2 months ago
}
})