mirror of
https://github.com/DavidHDev/vue-bits.git
synced 2026-03-07 14:39:30 -07:00
Add prettier config, format codebase
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import { ref } from 'vue'
|
||||
import { ref } from 'vue';
|
||||
|
||||
/**
|
||||
* Composable for force re-rendering components
|
||||
* Useful for demo components that need to restart animations or reset state
|
||||
*/
|
||||
export function useForceRerender() {
|
||||
const rerenderKey = ref(0)
|
||||
const rerenderKey = ref(0);
|
||||
|
||||
const forceRerender = () => {
|
||||
rerenderKey.value++
|
||||
}
|
||||
rerenderKey.value++;
|
||||
};
|
||||
|
||||
return {
|
||||
rerenderKey,
|
||||
forceRerender
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,48 +1,51 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { getStarsCount } from '@/utils/utils'
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { getStarsCount } from '@/utils/utils';
|
||||
|
||||
const CACHE_KEY = 'github_stars_cache'
|
||||
const CACHE_DURATION = 24 * 60 * 60 * 1000
|
||||
const CACHE_KEY = 'github_stars_cache';
|
||||
const CACHE_DURATION = 24 * 60 * 60 * 1000;
|
||||
|
||||
export function useStars() {
|
||||
const stars = ref<number>(0)
|
||||
const stars = ref<number>(0);
|
||||
|
||||
const fetchStars = async () => {
|
||||
try {
|
||||
const cachedData = localStorage.getItem(CACHE_KEY)
|
||||
|
||||
const cachedData = localStorage.getItem(CACHE_KEY);
|
||||
|
||||
if (cachedData) {
|
||||
const { count, timestamp } = JSON.parse(cachedData)
|
||||
const now = Date.now()
|
||||
|
||||
const { count, timestamp } = JSON.parse(cachedData);
|
||||
const now = Date.now();
|
||||
|
||||
if (now - timestamp < CACHE_DURATION) {
|
||||
stars.value = count
|
||||
return
|
||||
stars.value = count;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const count = await getStarsCount()
|
||||
|
||||
localStorage.setItem(CACHE_KEY, JSON.stringify({
|
||||
count,
|
||||
timestamp: Date.now()
|
||||
}))
|
||||
|
||||
stars.value = count
|
||||
|
||||
const count = await getStarsCount();
|
||||
|
||||
localStorage.setItem(
|
||||
CACHE_KEY,
|
||||
JSON.stringify({
|
||||
count,
|
||||
timestamp: Date.now()
|
||||
})
|
||||
);
|
||||
|
||||
stars.value = count;
|
||||
} catch (error) {
|
||||
console.error('Error fetching stars:', error)
|
||||
|
||||
const cachedData = localStorage.getItem(CACHE_KEY)
|
||||
console.error('Error fetching stars:', error);
|
||||
|
||||
const cachedData = localStorage.getItem(CACHE_KEY);
|
||||
if (cachedData) {
|
||||
const { count } = JSON.parse(cachedData)
|
||||
stars.value = count
|
||||
const { count } = JSON.parse(cachedData);
|
||||
stars.value = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
fetchStars()
|
||||
})
|
||||
fetchStars();
|
||||
});
|
||||
|
||||
return stars
|
||||
return stars;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user