Skip to content

Commit

Permalink
Fix app icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Janaka-Steph committed Sep 5, 2023
1 parent e4db5ca commit b972cad
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/modules/service/components/SearchFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { MultiValue } from "react-select";
import Select from "react-select";
import { serviceSearchStyle } from "shared/helpers/utils";

import useSettingStore from "../../../shared/store/setting";
import type { Option, SearchFilterProps } from "../types";
import api from "../../../shared/api/v1";
import type { App, Option, SearchFilterProps } from "../types";

import MultiValueRemove from "./MultiValueRemove";

Expand Down Expand Up @@ -49,6 +49,22 @@ const SearchFilter = ({ apps, onFilterChange, appId }: SearchFilterProps) => {
.map((app) => ({ value: app.id, label: app.name }));
}, [apps, search]);

const Image = (app: App) => {
const [imageSrc, setImageSrc] = useState("");
useEffect(() => {
(async () => {
const response = await api().get(app.icon.replace(/^\/+/, ""));
if (response.status === 200) {
const objectURL = URL.createObjectURL(response.data);
setImageSrc(objectURL);
} else {
console.error("Failed to fetch image");
}
})();
}, [app.icon]);
return imageSrc ? <img src={imageSrc} alt={app.name} className="mr-2 w-4 h-4 rounded" /> : null;
};

if (search.size === 0) return null;

return (
Expand Down Expand Up @@ -88,11 +104,7 @@ const SearchFilter = ({ apps, onFilterChange, appId }: SearchFilterProps) => {
className="flex px-2 py-[6px] items-center text-sm"
onClick={() => handleSearch(app.id)}
>
<img
src={`${useSettingStore.getState().backendUrl.replace(/\/$/, "")}${app.icon}`}
alt={app.name}
className="mr-2 w-4 h-4 rounded"
/>
<Image {...app} />
<span>{app.name}</span>
</button>
</div>
Expand Down

0 comments on commit b972cad

Please sign in to comment.