({
text: '',
});
-let lastRequestId = 0;
+let lastReq = 0;
-const skeletonCountFor = (list: PostResponse[]) => (list.length > 0 ? list.length : DEFAULT_SKELETON_COUNT);
+const getSkels = (list: PostResponse[]) => (list.length > 0 ? list.length : DEFAULT_SKELETON_COUNT);
-const fetchPosts = async () => {
- const requestId = ++lastRequestId;
+const loadPosts = async () => {
+ const reqId = ++lastReq;
- const previousItems = items.value;
- skeletonCount.value = skeletonCountFor(previousItems);
- isLoading.value = true;
+ const prevItems = items.value;
+ skelCnt.value = getSkels(prevItems);
+ isLoad.value = true;
try {
- const collection: PostsCollectionResponse = await apiStore.getPosts(filters);
+ const collection: PostsCollectionResponse = await api.getPosts(filters);
- if (requestId !== lastRequestId) {
+ if (reqId !== lastReq) {
return;
}
items.value = collection.data as PostResponse[];
} catch (error) {
debugError(error);
- if (requestId === lastRequestId) {
- items.value = previousItems.length > 0 ? previousItems : [];
+ if (reqId === lastReq) {
+ items.value = prevItems.length > 0 ? prevItems : [];
}
} finally {
- if (requestId === lastRequestId) {
- skeletonCount.value = skeletonCountFor(items.value);
- isLoading.value = false;
+ if (reqId === lastReq) {
+ skelCnt.value = getSkels(items.value);
+ isLoad.value = false;
}
}
};
// --- Categories' Filter:
-const debouncedFetchPosts = debounce(
+const debFetch = debounce(
() => {
- fetchPosts();
+ loadPosts();
},
500,
{ leading: true, trailing: true },
);
-const debouncedSearch = debounce(() => {
- fetchPosts();
+const debSearch = debounce(() => {
+ loadPosts();
}, 300);
watch(
() => filters.category,
() => {
- debouncedFetchPosts();
+ debFetch();
},
);
onBeforeUnmount(() => {
- debouncedFetchPosts.cancel();
- debouncedSearch.cancel();
+ debFetch.cancel();
+ debSearch.cancel();
});
// --- Search: filter post by the given search criteria.
watch(
- () => apiStore.searchTerm,
- (newSearchTerm: string): void => {
- const newText = newSearchTerm.trim();
+ () => api.searchTerm,
+ (nextTerm: string): void => {
+ const newText = nextTerm.trim();
const oldText = filters.text;
filters.text = newText;
if (newText && !oldText) {
// Starting search
- categoryBeforeSearch.value = filters.category ?? '';
+ prevCtg.value = filters.category ?? '';
filters.category = '';
} else if (!newText && oldText) {
// Clearing search
- filters.category = categoryBeforeSearch.value;
- categoryBeforeSearch.value = '';
+ filters.category = prevCtg.value;
+ prevCtg.value = '';
}
if (!filters.text && !filters.category && categories.value.length > 0) {
filters.category = categories.value[0].slug;
}
- debouncedSearch();
+ debSearch();
},
);
// --- Mount the Vue component
onMounted(async () => {
try {
- categoriesCollection.value = await apiStore.getCategories();
- categories.value = categoriesCollection.value.data as CategoryResponse[];
+ categsRes.value = await api.getCategories();
+ categories.value = categsRes.value.data as CategoryResponse[];
if (categories.value.length > 0) {
filters.category = categories.value[0].slug;
diff --git a/src/partials/FooterPartial.vue b/src/partials/Footer.vue
similarity index 100%
rename from src/partials/FooterPartial.vue
rename to src/partials/Footer.vue
diff --git a/src/partials/HeroPartial.vue b/src/partials/Hero.vue
similarity index 97%
rename from src/partials/HeroPartial.vue
rename to src/partials/Hero.vue
index 63da3f31..7f2a746c 100644
--- a/src/partials/HeroPartial.vue
+++ b/src/partials/Hero.vue
@@ -63,7 +63,7 @@
diff --git a/src/partials/PostPageSkeletonPartial.vue b/src/partials/PostPgSkl.vue
similarity index 100%
rename from src/partials/PostPageSkeletonPartial.vue
rename to src/partials/PostPgSkl.vue
diff --git a/src/partials/ProjectCardPartial.vue b/src/partials/ProjCard.vue
similarity index 100%
rename from src/partials/ProjectCardPartial.vue
rename to src/partials/ProjCard.vue
diff --git a/src/partials/ProjectCardSkeletonPartial.vue b/src/partials/ProjCardSk.vue
similarity index 100%
rename from src/partials/ProjectCardSkeletonPartial.vue
rename to src/partials/ProjCardSk.vue
diff --git a/src/partials/RecommendationDialogSkeletonPartial.vue b/src/partials/RecDlgSkel.vue
similarity index 100%
rename from src/partials/RecommendationDialogSkeletonPartial.vue
rename to src/partials/RecDlgSkel.vue
diff --git a/src/partials/RecommendationPartial.vue b/src/partials/RecomPart.vue
similarity index 54%
rename from src/partials/RecommendationPartial.vue
rename to src/partials/RecomPart.vue
index 1ba43ffe..9583aa10 100644
--- a/src/partials/RecommendationPartial.vue
+++ b/src/partials/RecomPart.vue
@@ -8,11 +8,11 @@