Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
KartVen committed Dec 3, 2024
2 parents cddb652 + 55ca05d commit b283f57
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint --format stylish",
"format": "prettier --write ."
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx}'"
},
"lint-staged": {
"src/**/*.{js,ts,tsx}": [
Expand Down
9 changes: 5 additions & 4 deletions src/components/layout/navbar/middle/SearchBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ export default function SearchBlock() {
page: 1,
size: DEFAULT_PAGE_SIZE,
sort: MaterialSortField.ID,
sort_direction: SortDirection.ASC
sort_direction: SortDirection.ASC,
};

const { data: materials, status, fetch: fetchMaterials } = useFetchState<Pageable<MaterialSearch>>();

if (!isOpen) return <></>;

useEffect(() => {
isOpen && fetchMaterials(() => {
return MaterialService.getMaterials(searchParams);
});
isOpen &&
fetchMaterials(() => {
return MaterialService.getMaterials(searchParams);
});
}, []);

if (status === Status.PENDING)
Expand Down
20 changes: 6 additions & 14 deletions src/services/material/materialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export const MaterialSwaggerStatuses = {
BANNED: 'BANNED',
DEPRECATION_REQUEST: 'DEPRECATION_REQUEST',
DEPRECATED: 'DEPRECATED',
DELETED: 'DELETED'
DELETED: 'DELETED',
} as const;

export type MaterialSwaggerStatus = keyof typeof MaterialSwaggerStatuses;

export default class MaterialService extends ApiService {
public static async getMaterials(
params: SearchRequestParams<MaterialSortField, MaterialFiltersParam>
params: SearchRequestParams<MaterialSortField, MaterialFiltersParam>,
): Promise<Pageable<MaterialSearch>> {
const { size, page, sort, sort_direction, filters } = params;

Expand All @@ -30,7 +30,7 @@ export default class MaterialService extends ApiService {
page: page > 0 ? (page - 1).toString() : '0',
sort: MaterialSortField[sort],
sort_direction: SortDirection[sort_direction],
filters: filters ? JSON.stringify(filters) : '{}'
filters: filters ? JSON.stringify(filters) : '{}',
});

try {
Expand All @@ -57,10 +57,7 @@ export default class MaterialService extends ApiService {
}
}

public static async addGradeToMaterial(
materialId: number,
grade: MaterialAddGrade
): Promise<MaterialAddGrade> {
public static async addGradeToMaterial(materialId: number, grade: MaterialAddGrade): Promise<MaterialAddGrade> {
try {
const response = await kodemyApi.post<MaterialAddGrade>(`/api/materials/${materialId}/grades`, grade);
return response.data;
Expand All @@ -69,14 +66,9 @@ export default class MaterialService extends ApiService {
}
}

public static async changeMaterialStatus(
materialId: number,
newStatus: MaterialSwaggerStatus
): Promise<Material> {
public static async changeMaterialStatus(materialId: number, newStatus: MaterialSwaggerStatus): Promise<Material> {
try {
const response = await kodemyApi.post<Material>(
`/api/materials/${materialId}/status`, { status: newStatus }
);
const response = await kodemyApi.post<Material>(`/api/materials/${materialId}/status`, { status: newStatus });
return response.data;
} catch (err) {
return Promise.reject(new InternalServerErrorApiError());
Expand Down

0 comments on commit b283f57

Please sign in to comment.