Skip to content

Commit

Permalink
Refactor icon mask logic into unified helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jmetrikat committed Feb 10, 2025
1 parent caa1667 commit d8efffa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/components/ObjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MutatePromise } from "@raycast/utils";
import { format } from "date-fns";
import { useEffect, useState } from "react";
import { localStorageKeys } from "../helpers/constants";
import { getMaskForObject } from "../helpers/icon";
import { Member, SpaceObject, Type } from "../helpers/schemas";
import { getDateLabel, getShortDateLabel, pluralize } from "../helpers/strings";
import { useMembers } from "../hooks/useMembers";
Expand Down Expand Up @@ -92,10 +93,7 @@ export default function ObjectList({ spaceId }: ObjectListProps) {
objectId: object.id,
icon: {
source: object.icon,
mask:
(object.layout === "participant" || object.layout === "profile") && object.icon != Icon.Document
? Image.Mask.Circle
: Image.Mask.RoundedRectangle,
mask: getMaskForObject(object.layout, object.icon),
},
title: object.name,
subtitle: {
Expand Down
11 changes: 10 additions & 1 deletion src/helpers/icon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Icon } from "@raycast/api";
import { Icon, Image } from "@raycast/api";
import fetch from "node-fetch";
import { iconWidth } from "./constants";

Expand Down Expand Up @@ -58,3 +58,12 @@ export async function fetchWithTimeout(url: string, timeout: number): Promise<st

return undefined;
}

/**
* Determine which mask to use for a given Object.
*/
export function getMaskForObject(layout: string, icon: string): Image.Mask {
return (layout === "participant" || layout === "profile") && icon != Icon.Document
? Image.Mask.Circle
: Image.Mask.RoundedRectangle;
}
6 changes: 2 additions & 4 deletions src/search-anytype.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import EmptyView from "./components/EmptyView";
import EnsureAuthenticated from "./components/EnsureAuthenticated";
import ObjectListItem from "./components/ObjectListItem";
import { localStorageKeys } from "./helpers/constants";
import { getMaskForObject } from "./helpers/icon";
import { Member, SpaceObject, Type } from "./helpers/schemas";
import { getDateLabel, getShortDateLabel, pluralize } from "./helpers/strings";
import { getAllTypesFromSpaces } from "./helpers/types";
Expand Down Expand Up @@ -130,10 +131,7 @@ function Search() {
objectId: object.id,
icon: {
source: object.icon,
mask:
(object.layout === "participant" || object.layout === "profile") && object.icon != Icon.Document
? Image.Mask.Circle
: Image.Mask.RoundedRectangle,
mask: getMaskForObject(object.layout, object.icon),
},
title: object.name,
subtitle: {
Expand Down

0 comments on commit d8efffa

Please sign in to comment.