Initial commit - modstagram-next

This commit is contained in:
root
2026-07-05 13:59:41 +03:30
commit 11e73da693
859 changed files with 117640 additions and 0 deletions

44
src/api/fetchPosts.ts Normal file
View File

@@ -0,0 +1,44 @@
import { BASE_URL } from "@/components/main/BaseUrl";
export async function fetchPosts(
page: number,
limit: number,
filters: {
expertise?: string;
province?: string;
city?: string;
userLevel?: string;
rateFilter?: string;
_id?: string;
type?: string;
},
token: string
) {
const validFilters = Object.entries(filters || {})
.filter(([value]) => value !== undefined && value !== "")
.reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {} as Record<string, string>);
const queryParams = new URLSearchParams({
page: page.toString(),
limit: limit.toString(),
...validFilters,
}).toString();
const apiUrl = `${BASE_URL}/users/web?${queryParams}`;
const response = await fetch(apiUrl, {
cache: "no-store",
headers: {
Authorization: token ? `Bearer ${token}` : "",
},
});
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.status}`);
}
return response.json();
}