Skip to content

Commit

Permalink
added sorting by relevance
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Nov 23, 2024
1 parent 39dc808 commit 605566d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/app/modules/components/asyncImage.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const AsyncImage = (src: string): Promise<HTMLImageElement> =>
img.src = src;

img.onload = () => resolve(img);
img.onerror = () => reject(new Error("Failed to load image"));
img.onerror = reject;
});

export const base64Encode = (img: HTMLImageElement) => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.height = img.naturalHeight;
canvas.width = img.naturalWidth;
ctx.drawImage(this, 0, 0);
ctx.drawImage(img, 0, 0);
return canvas.toDataURL();
}

Expand Down
7 changes: 4 additions & 3 deletions src/app/modules/components/search.module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const options: readonly { value: number, label: String }[] = [
];

const options_sortir: readonly { value: string, label: String }[] = [
{ value: 'popular_up', label: "По популярности" },
{ value: 'date_up', label: "По дате создания" },
{ value: 'name_up', label: "По имени" }
{ value: 'popular_up', label: 'По популярности' },
{ value: 'relevant_up', label: 'По релевантности' },
{ value: 'date_up', label: 'По дате создания' },
{ value: 'name_up', label: 'По имени' }
];

interface SearchProps {
Expand Down
31 changes: 13 additions & 18 deletions src/app/workshop/[id]/bandage_engine.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncImage from '@/app/modules/components/asyncImage.module';
import asyncImage, { base64Encode } from '@/app/modules/components/asyncImage.module';
import ApiManager from '@/app/modules/utils/apiManager';
import axios from 'axios';

interface SkinResponse {
data: {
Expand Down Expand Up @@ -104,23 +103,19 @@ class Client {
}

loadSkinUrl(url: string) {
axios.get(url, { responseType: 'blob' }).then((result => {
if (result.status === 200) {
const reader = new FileReader();
reader.onloadend = () => {
this.setOriginalCanvas(reader.result as string);

this.addEventListener("onload", () => {
this.skin = reader.result as string;
this.rerender();
this.removeEventListener("onload");
});
}
reader.readAsDataURL(result.data);
}
}))
}
asyncImage(url)
.then(img => {
const base64 = base64Encode(img);
this.setOriginalCanvas(base64);

this.addEventListener("onload", () => {
this.skin = base64;
this.rerender();
this.removeEventListener("onload");
});
})
.catch(console.error);
}

triggerEvent(property: string) {
if (property === 'rerender' || this.listeners[property]) {
Expand Down

0 comments on commit 605566d

Please sign in to comment.