|
|
@ -1,16 +1,12 @@ |
|
|
|
import axios from 'axios' |
|
|
|
|
|
|
|
import type { ProductFeedItem } from '../lib/types' |
|
|
|
import type { ProductFeedItem } from '../lib/types' |
|
|
|
|
|
|
|
|
|
|
|
const axiosInstance = axios.create({ |
|
|
|
|
|
|
|
baseURL: 'https://nocodb.com/api/v1', |
|
|
|
|
|
|
|
headers: { |
|
|
|
|
|
|
|
'Content-Type': 'application/json', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const useProductFeed = createSharedComposable(() => { |
|
|
|
export const useProductFeed = createSharedComposable(() => { |
|
|
|
const activeTab = ref('recents') |
|
|
|
const activeTab = ref('recents') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { appInfo } = useGlobal() |
|
|
|
|
|
|
|
|
|
|
|
const youtubeFeed = ref<ProductFeedItem[]>([]) |
|
|
|
const youtubeFeed = ref<ProductFeedItem[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const githubFeed = ref<ProductFeedItem[]>([]) |
|
|
|
const githubFeed = ref<ProductFeedItem[]>([]) |
|
|
@ -23,7 +19,9 @@ export const useProductFeed = createSharedComposable(() => { |
|
|
|
social: false, |
|
|
|
social: false, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const loadFeed = async ({ loadMore, type }: { loadMore: boolean; type: 'youtube' | 'github' | 'all' | 'twitter' }) => { |
|
|
|
const newFeedCount = ref(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const loadFeed = async ({ loadMore, type }: { loadMore: boolean; type: 'youtube' | 'github' | 'all' }) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
let page = 1 |
|
|
|
let page = 1 |
|
|
|
|
|
|
|
|
|
|
@ -41,15 +39,13 @@ export const useProductFeed = createSharedComposable(() => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const response = await axiosInstance.get<ProductFeedItem[]>('/social/feed', { |
|
|
|
const response = await $api.utils.feed2({ page, per_page: 10, type }) |
|
|
|
params: { |
|
|
|
|
|
|
|
per_page: 10, |
|
|
|
if (type === 'all' && page === 1 && response.length) { |
|
|
|
page, |
|
|
|
localStorage.setItem('last_published_at', response[0]['Published Time'] as string) |
|
|
|
type, |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response.data |
|
|
|
return response |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
switch (type) { |
|
|
|
switch (type) { |
|
|
|
case 'youtube': |
|
|
|
case 'youtube': |
|
|
@ -67,6 +63,39 @@ export const useProductFeed = createSharedComposable(() => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const checkForNewFeed = async () => { |
|
|
|
|
|
|
|
const lastPublishedAt = localStorage.getItem('last_published_at') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!lastPublishedAt) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const newFeeds = await $api.utils.feed({ last_published_at: lastPublishedAt }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newFeedCount.value = newFeeds as unknown as number |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
console.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const intervalId = ref() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const checkFeedWithInterval = async () => { |
|
|
|
|
|
|
|
await checkForNewFeed() |
|
|
|
|
|
|
|
intervalId.value = setTimeout(checkFeedWithInterval, 3 * 60 * 60 * 1000) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
|
|
|
|
if (appInfo.value.feedEnabled) { |
|
|
|
|
|
|
|
checkFeedWithInterval() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => { |
|
|
|
|
|
|
|
if (intervalId) clearTimeout(intervalId.value) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
isErrorOccurred, |
|
|
|
isErrorOccurred, |
|
|
|
activeTab, |
|
|
|
activeTab, |
|
|
|