learning
This commit is contained in:
@@ -1,78 +1,17 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
// import * as api from "../service/LearningService";
|
import * as api from "../service/LearningService";
|
||||||
import {
|
|
||||||
staticLearningsData,
|
|
||||||
staticLearningDetailData,
|
|
||||||
} from "../data/staticData";
|
|
||||||
|
|
||||||
export const useGetLearnings = (search: string, limit?: number) => {
|
export const useGetLearnings = (search: string, limit?: number) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["learnings", search, limit],
|
queryKey: ["learnings", search, limit],
|
||||||
// queryFn: () => api.getLearnings(search, limit),
|
queryFn: () => api.getLearnings(search, limit),
|
||||||
queryFn: () => {
|
|
||||||
// شبیهسازی delay سرور
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
let filteredData = staticLearningsData;
|
|
||||||
|
|
||||||
// فیلتر کردن بر اساس جستجو
|
|
||||||
if (search) {
|
|
||||||
filteredData = {
|
|
||||||
data: {
|
|
||||||
learnings: staticLearningsData.data.learnings.filter(
|
|
||||||
(item) =>
|
|
||||||
item.title.toLowerCase().includes(search.toLowerCase()) ||
|
|
||||||
item.description
|
|
||||||
.toLowerCase()
|
|
||||||
.includes(search.toLowerCase()) ||
|
|
||||||
item.category.name
|
|
||||||
.toLowerCase()
|
|
||||||
.includes(search.toLowerCase())
|
|
||||||
),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// محدود کردن تعداد نتایج
|
|
||||||
if (limit) {
|
|
||||||
filteredData = {
|
|
||||||
data: {
|
|
||||||
learnings: filteredData.data.learnings.slice(0, limit),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(filteredData);
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetLearningDetail = (id: string) => {
|
export const useGetLearningDetail = (id: string) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["learning", id],
|
queryKey: ["learning", id],
|
||||||
// queryFn: () => api.getLearningDetail(id),
|
queryFn: () => api.getLearningDetail(id),
|
||||||
queryFn: () => {
|
|
||||||
// شبیهسازی delay سرور
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
// پیدا کردن آموزش بر اساس ID
|
|
||||||
const learning = staticLearningsData.data.learnings.find(
|
|
||||||
(item) => item.id === id
|
|
||||||
);
|
|
||||||
if (learning) {
|
|
||||||
resolve({
|
|
||||||
data: {
|
|
||||||
learning: learning,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
resolve(staticLearningDetailData);
|
|
||||||
}
|
|
||||||
}, 300);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
enabled: !!id,
|
enabled: !!id,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
// import axios from "../../../config/axios";
|
import axios from "../../../config/axios";
|
||||||
|
|
||||||
// Service calls کامنت شده - در حال حاضر از دیتای استاتیک استفاده میشود
|
export const getLearnings = async (search: string, limit?: number) => {
|
||||||
// export const getLearnings = async (search: string, limit?: number) => {
|
const { data } = await axios.get(
|
||||||
// const { data } = await axios.get(
|
`/public/learnings?q=${search}&limit=${limit ? limit : 20}`,
|
||||||
// `/learnings?q=${search}&limit=${limit ? limit : 20}`
|
);
|
||||||
// );
|
return data;
|
||||||
// return data;
|
};
|
||||||
// };
|
|
||||||
|
|
||||||
// export const getLearningDetail = async (id: string) => {
|
export const getLearningDetail = async (id: string) => {
|
||||||
// const { data } = await axios.get(`/learnings/${id}`);
|
const { data } = await axios.get(`/public/learnings/${id}`);
|
||||||
// return data;
|
return data;
|
||||||
// };
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user