Skip to content

Commit 17fe9ff

Browse files
fix(mobile): render assigned project icons in chat list
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 9f73ca3 commit 17fe9ff

8 files changed

Lines changed: 184 additions & 2 deletions

File tree

‎apps/mobile/src/components/ProjectFavicon.tsx‎

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { SymbolView } from "./AppSymbol";
2+
import { AppText } from "./AppText";
23
import { Image } from "expo-image";
34
import { useLayoutEffect, useMemo, useState } from "react";
45
import { View } from "react-native";
5-
import type { EnvironmentId } from "@t3tools/contracts";
6+
import type { EnvironmentId, ProjectIconOverride } from "@t3tools/contracts";
67
import {
78
getProjectFaviconCacheKey,
89
getProjectFaviconResourceKey,
@@ -11,6 +12,12 @@ import {
1112
import { useAtomValue } from "@effect/atom-react";
1213
import { Atom } from "effect/unstable/reactivity";
1314
import { projectFaviconUrlAtom } from "../state/assets";
15+
import {
16+
countGlyphs,
17+
projectIconColorClassNames,
18+
resolveProjectIconGlyph,
19+
type ProjectIconGlyph,
20+
} from "../lib/projectIcon";
1421

1522
import {
1623
beginProjectFaviconRequest,
@@ -30,10 +37,12 @@ export function ProjectFavicon(props: {
3037
readonly projectTitle: string;
3138
readonly workspaceRoot?: string | null;
3239
readonly faviconPath?: string | null;
40+
readonly projectIcon?: ProjectIconOverride | null;
3341
}) {
3442
const size = props.size ?? 42;
43+
const glyph = resolveProjectIconGlyph(props.projectIcon, props.projectTitle);
3544
const faviconUrl = useAtomValue(
36-
props.workspaceRoot == null
45+
props.workspaceRoot == null || glyph !== null
3746
? EMPTY_FAVICON_URL
3847
: projectFaviconUrlAtom({
3948
environmentId: props.environmentId,
@@ -51,6 +60,10 @@ export function ProjectFavicon(props: {
5160
: getProjectFaviconCacheKey(props.environmentId, props.workspaceRoot, renderableFaviconUrl)
5261
: null;
5362

63+
if (glyph !== null) {
64+
return <ProjectIconGlyphView glyph={glyph} size={size} />;
65+
}
66+
5467
return (
5568
<ProjectFaviconImage
5669
key={cacheKey}
@@ -63,6 +76,51 @@ export function ProjectFavicon(props: {
6376
);
6477
}
6578

79+
function ProjectIconGlyphView(props: { readonly glyph: ProjectIconGlyph; readonly size: number }) {
80+
const { glyph, size } = props;
81+
if (glyph.kind === "emoji") {
82+
return (
83+
<View style={{ width: size, height: size, alignItems: "center", justifyContent: "center" }}>
84+
<AppText
85+
allowFontScaling={false}
86+
numberOfLines={1}
87+
style={{ fontSize: size * 0.7, lineHeight: size, textAlign: "center" }}
88+
>
89+
{glyph.emoji}
90+
</AppText>
91+
</View>
92+
);
93+
}
94+
95+
const colors = projectIconColorClassNames(glyph.color);
96+
return (
97+
<View
98+
className={colors.background}
99+
style={{
100+
width: size,
101+
height: size,
102+
borderRadius: size * 0.25,
103+
alignItems: "center",
104+
justifyContent: "center",
105+
}}
106+
>
107+
<AppText
108+
allowFontScaling={false}
109+
numberOfLines={1}
110+
className={`font-mono ${colors.text}`}
111+
style={{
112+
fontWeight: "700",
113+
fontSize: size * (countGlyphs(glyph.text) === 1 ? 0.6 : 0.48),
114+
lineHeight: size,
115+
textAlign: "center",
116+
}}
117+
>
118+
{glyph.text}
119+
</AppText>
120+
</View>
121+
);
122+
}
123+
66124
function ProjectFaviconImage(props: {
67125
readonly cacheKey: string | null;
68126
readonly faviconUrl: string | null;

‎apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ function ProjectGroupLabel(props: {
151151
<ProjectFavicon
152152
environmentId={props.project.environmentId}
153153
faviconPath={props.project.faviconPath}
154+
projectIcon={props.project.projectIcon}
154155
projectTitle={props.project.title}
155156
size={18}
156157
workspaceRoot={props.project.workspaceRoot}

‎apps/mobile/src/features/settings/SettingsProjectOverviewRouteScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function ProjectOverviewContent(props: {
9999
projectTitle={displayName}
100100
workspaceRoot={representative.workspaceRoot}
101101
faviconPath={representative.faviconPath}
102+
projectIcon={representative.projectIcon}
102103
size={48}
103104
/>
104105
<View className="min-w-0 flex-1">

‎apps/mobile/src/features/threads/NewTaskRouteScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
333333
<ProjectFavicon
334334
environmentId={scope.representative.environmentId}
335335
faviconPath={scope.representative.faviconPath}
336+
projectIcon={scope.representative.projectIcon}
336337
size={24}
337338
projectTitle={scope.title}
338339
workspaceRoot={scope.representative.workspaceRoot}
@@ -357,6 +358,7 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
357358
<ProjectFavicon
358359
environmentId={scope.representative.environmentId}
359360
faviconPath={scope.representative.faviconPath}
361+
projectIcon={scope.representative.projectIcon}
360362
size={20}
361363
projectTitle={scope.title}
362364
workspaceRoot={scope.representative.workspaceRoot}

‎apps/mobile/src/features/threads/thread-list-items.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export const ThreadListGroupHeader = memo(function ThreadListGroupHeader(props:
148148
<ProjectFavicon
149149
environmentId={props.project.environmentId}
150150
faviconPath={props.project.faviconPath}
151+
projectIcon={props.project.projectIcon}
151152
open={!props.collapsed}
152153
size={compact ? 22 : 18}
153154
projectTitle={props.project.title}

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export const ThreadListV2PendingRow = memo(function ThreadListV2PendingRow(props
300300
<ProjectFavicon
301301
environmentId={pendingTask.environmentId}
302302
faviconPath={props.project.faviconPath}
303+
projectIcon={props.project.projectIcon}
303304
size={15}
304305
projectTitle={projectTitle}
305306
workspaceRoot={props.project.workspaceRoot}
@@ -831,6 +832,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
831832
<ProjectFavicon
832833
environmentId={thread.environmentId}
833834
faviconPath={props.project.faviconPath}
835+
projectIcon={props.project.projectIcon}
834836
size={15}
835837
projectTitle={props.projectTitle ?? props.project.title}
836838
workspaceRoot={props.project.workspaceRoot}
@@ -1065,6 +1067,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
10651067
<ProjectFavicon
10661068
environmentId={thread.environmentId}
10671069
faviconPath={props.project.faviconPath}
1070+
projectIcon={props.project.projectIcon}
10681071
size={15}
10691072
projectTitle={props.projectTitle ?? props.project.title}
10701073
workspaceRoot={props.project.workspaceRoot}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { projectMonogram, resolveProjectIconGlyph } from "./projectIcon";
4+
5+
describe("resolveProjectIconGlyph", () => {
6+
it("returns null without an override so the favicon path is used", () => {
7+
expect(resolveProjectIconGlyph(null, "nebula")).toBeNull();
8+
expect(resolveProjectIconGlyph(undefined, "nebula")).toBeNull();
9+
});
10+
11+
it("passes emoji and monogram overrides through", () => {
12+
expect(resolveProjectIconGlyph({ kind: "emoji", emoji: "🍎" }, "silver-orchard")).toEqual({
13+
kind: "emoji",
14+
emoji: "🍎",
15+
});
16+
expect(
17+
resolveProjectIconGlyph({ kind: "monogram", text: "M7", color: "orange" }, "m7-forge"),
18+
).toEqual({ kind: "monogram", text: "M7", color: "orange" });
19+
});
20+
21+
it("turns a lucide override into a monogram that keeps the chosen color", () => {
22+
expect(
23+
resolveProjectIconGlyph({ kind: "lucide", name: "rocket", color: "violet" }, "nebula"),
24+
).toEqual({ kind: "monogram", text: "NA", color: "violet" });
25+
});
26+
});
27+
28+
describe("projectMonogram", () => {
29+
it.each([
30+
["nebula", "NA"],
31+
["silver-orchard", "SO"],
32+
["m7-forge", "M7"],
33+
["t3code", "T3"],
34+
[" ", "PR"],
35+
])("derives %s -> %s", (title, expected) => {
36+
expect(projectMonogram(title)).toBe(expected);
37+
});
38+
});

‎apps/mobile/src/lib/projectIcon.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import type { ProjectIconColor, ProjectIconOverride } from "@t3tools/contracts";
2+
3+
export type ProjectIconGlyph =
4+
| { readonly kind: "emoji"; readonly emoji: string }
5+
| { readonly kind: "monogram"; readonly text: string; readonly color: ProjectIconColor };
6+
7+
/** Code point count; Hermes has no Intl.Segmenter, and monogram text is at most two glyphs. */
8+
export function countGlyphs(text: string): number {
9+
return Array.from(text).length;
10+
}
11+
12+
/** Mirrors the automatic monogram web derives from a project name when it has no favicon. */
13+
export function projectMonogram(projectName: string): string {
14+
const words =
15+
projectName
16+
.normalize("NFKC")
17+
.trim()
18+
.match(/[\p{L}\p{N}]+/gu) ?? [];
19+
const firstWord = words[0];
20+
if (!firstWord) return "PR";
21+
22+
const glyphs = Array.from(firstWord);
23+
const first = glyphs[0] ?? "P";
24+
const second =
25+
glyphs.slice(1).find((glyph) => /\p{N}/u.test(glyph)) ??
26+
(words.length > 1 ? Array.from(words.at(-1) ?? "")[0] : glyphs.at(-1)) ??
27+
first;
28+
return Array.from(`${first}${second}`.toUpperCase()).slice(0, 2).join("");
29+
}
30+
31+
/**
32+
* Picks what mobile draws for an assigned project icon. Mobile does not bundle
33+
* the Lucide set, so a Lucide override keeps its color and falls back to the
34+
* project's monogram instead of the folder glyph.
35+
*/
36+
export function resolveProjectIconGlyph(
37+
projectIcon: ProjectIconOverride | null | undefined,
38+
projectTitle: string,
39+
): ProjectIconGlyph | null {
40+
switch (projectIcon?.kind) {
41+
case "emoji":
42+
return { kind: "emoji", emoji: projectIcon.emoji };
43+
case "monogram":
44+
return { kind: "monogram", text: projectIcon.text, color: projectIcon.color };
45+
case "lucide":
46+
return { kind: "monogram", text: projectMonogram(projectTitle), color: projectIcon.color };
47+
case undefined:
48+
return null;
49+
}
50+
}
51+
52+
const PROJECT_ICON_COLOR_CLASSES: Record<
53+
ProjectIconColor,
54+
{ readonly text: string; readonly background: string }
55+
> = {
56+
gray: { text: "text-gray-500", background: "bg-gray-500/15" },
57+
red: { text: "text-red-500", background: "bg-red-500/15" },
58+
orange: { text: "text-orange-500", background: "bg-orange-500/15" },
59+
amber: { text: "text-amber-500", background: "bg-amber-500/15" },
60+
yellow: { text: "text-yellow-500", background: "bg-yellow-500/15" },
61+
lime: { text: "text-lime-500", background: "bg-lime-500/15" },
62+
green: { text: "text-green-500", background: "bg-green-500/15" },
63+
emerald: { text: "text-emerald-500", background: "bg-emerald-500/15" },
64+
teal: { text: "text-teal-500", background: "bg-teal-500/15" },
65+
cyan: { text: "text-cyan-500", background: "bg-cyan-500/15" },
66+
sky: { text: "text-sky-500", background: "bg-sky-500/15" },
67+
blue: { text: "text-blue-500", background: "bg-blue-500/15" },
68+
indigo: { text: "text-indigo-500", background: "bg-indigo-500/15" },
69+
violet: { text: "text-violet-500", background: "bg-violet-500/15" },
70+
purple: { text: "text-purple-500", background: "bg-purple-500/15" },
71+
fuchsia: { text: "text-fuchsia-500", background: "bg-fuchsia-500/15" },
72+
pink: { text: "text-pink-500", background: "bg-pink-500/15" },
73+
rose: { text: "text-rose-500", background: "bg-rose-500/15" },
74+
};
75+
76+
export function projectIconColorClassNames(color: ProjectIconColor) {
77+
return PROJECT_ICON_COLOR_CLASSES[color];
78+
}

0 commit comments

Comments
 (0)