Skip to content

Commit a6c152e

Browse files
committed
chores
1 parent 8b7f901 commit a6c152e

File tree

10 files changed

+213
-169
lines changed

10 files changed

+213
-169
lines changed

apps/desktop/src/components/devtool/seed/shared/chat-shortcut.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const createChatShortcut = (): {
1212
id: id(),
1313
data: {
1414
user_id: DEFAULT_USER_ID,
15+
title: faker.lorem.words({ min: 2, max: 4 }),
1516
content: faker.lorem.sentence({ min: 3, max: 8 }),
1617
created_at: faker.date.past({ years: 1 }).toISOString(),
1718
},

apps/desktop/src/components/main/body/chat-shortcuts/details.tsx

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCallback, useEffect, useState } from "react";
22

33
import { Button } from "@hypr/ui/components/ui/button";
4+
import { Input } from "@hypr/ui/components/ui/input";
45
import { Textarea } from "@hypr/ui/components/ui/textarea";
56

67
import * as main from "../../../../store/tinybase/main";
@@ -95,22 +96,25 @@ function ChatShortcutForm({
9596
id: string;
9697
setSelectedMineId: (id: string | null) => void;
9798
}) {
99+
const title = main.UI.useCell("chat_shortcuts", id, "title", main.STORE_ID);
98100
const content = main.UI.useCell(
99101
"chat_shortcuts",
100102
id,
101103
"content",
102104
main.STORE_ID,
103105
);
104-
const [localValue, setLocalValue] = useState(content || "");
106+
const [localTitle, setLocalTitle] = useState(title || "");
107+
const [localContent, setLocalContent] = useState(content || "");
105108

106109
useEffect(() => {
107-
setLocalValue(content || "");
108-
}, [content, id]);
110+
setLocalTitle(title || "");
111+
setLocalContent(content || "");
112+
}, [title, content, id]);
109113

110114
const handleUpdate = main.UI.useSetPartialRowCallback(
111115
"chat_shortcuts",
112116
id,
113-
(row: { content?: string }) => row,
117+
(row: { title?: string; content?: string }) => row,
114118
[id],
115119
main.STORE_ID,
116120
);
@@ -122,15 +126,16 @@ function ChatShortcutForm({
122126
);
123127

124128
const handleSave = useCallback(() => {
125-
handleUpdate({ content: localValue });
126-
}, [handleUpdate, localValue]);
129+
handleUpdate({ title: localTitle, content: localContent });
130+
}, [handleUpdate, localTitle, localContent]);
127131

128132
const handleDeleteClick = useCallback(() => {
129133
handleDelete();
130134
setSelectedMineId(null);
131135
}, [handleDelete, setSelectedMineId]);
132136

133-
const hasChanges = localValue !== (content || "");
137+
const hasChanges =
138+
localTitle !== (title || "") || localContent !== (content || "");
134139

135140
return (
136141
<div className="flex flex-col h-full">
@@ -150,13 +155,28 @@ function ChatShortcutForm({
150155
</div>
151156
</div>
152157

153-
<div className="flex-1 p-6">
154-
<Textarea
155-
value={localValue}
156-
onChange={(e) => setLocalValue(e.target.value)}
157-
placeholder="Enter your chat shortcut content..."
158-
className="min-h-[200px] resize-none"
159-
/>
158+
<div className="flex-1 p-6 space-y-4">
159+
<div>
160+
<label className="text-sm font-medium text-neutral-700 mb-1.5 block">
161+
Title
162+
</label>
163+
<Input
164+
value={localTitle}
165+
onChange={(e) => setLocalTitle(e.target.value)}
166+
placeholder="Enter a title for this shortcut..."
167+
/>
168+
</div>
169+
<div>
170+
<label className="text-sm font-medium text-neutral-700 mb-1.5 block">
171+
Content
172+
</label>
173+
<Textarea
174+
value={localContent}
175+
onChange={(e) => setLocalContent(e.target.value)}
176+
placeholder="Enter your chat shortcut content..."
177+
className="min-h-[200px] resize-none"
178+
/>
179+
</div>
160180
</div>
161181

162182
<div className="p-6 border-t border-neutral-200">

apps/desktop/src/components/main/body/chat-shortcuts/index.tsx

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const TabItemChatShortcut: TabItem<
3131
return (
3232
<TabItemBase
3333
icon={<MessageSquare className="w-4 h-4" />}
34-
title={"Chat Shortcuts"}
34+
title="Shortcuts"
3535
selected={tab.active}
3636
tabIndex={tabIndex}
3737
handleCloseThis={() => handleCloseThis(tab)}
@@ -131,16 +131,23 @@ function ChatShortcutView({
131131

132132
const setRow = main.UI.useSetRowCallback(
133133
"chat_shortcuts",
134-
(p: { id: string; user_id: string; created_at: string; content: string }) =>
135-
p.id,
136134
(p: {
137135
id: string;
138136
user_id: string;
139137
created_at: string;
138+
title: string;
139+
content: string;
140+
}) => p.id,
141+
(p: {
142+
id: string;
143+
user_id: string;
144+
created_at: string;
145+
title: string;
140146
content: string;
141147
}) => ({
142148
user_id: p.user_id,
143149
created_at: p.created_at,
150+
title: p.title,
144151
content: p.content,
145152
}),
146153
[],
@@ -154,11 +161,21 @@ function ChatShortcutView({
154161
const newId = crypto.randomUUID();
155162
const now = new Date().toISOString();
156163

157-
setRow({ id: newId, user_id, created_at: now, content: shortcut.prompt });
158-
setIsWebMode(false);
159-
setSelectedMineId(newId);
164+
setRow({
165+
id: newId,
166+
user_id,
167+
created_at: now,
168+
title: shortcut.title,
169+
content: shortcut.prompt,
170+
});
171+
172+
updateTabState(tab, {
173+
isWebMode: false,
174+
selectedMineId: newId,
175+
selectedWebIndex: null,
176+
});
160177
},
161-
[user_id, setRow, setIsWebMode, setSelectedMineId],
178+
[user_id, setRow, updateTabState, tab],
162179
);
163180

164181
const handleAddNew = useCallback(() => {
@@ -167,10 +184,14 @@ function ChatShortcutView({
167184
const newId = crypto.randomUUID();
168185
const now = new Date().toISOString();
169186

170-
setRow({ id: newId, user_id, created_at: now, content: "" });
171-
setIsWebMode(false);
172-
setSelectedMineId(newId);
173-
}, [user_id, setRow, setIsWebMode, setSelectedMineId]);
187+
setRow({ id: newId, user_id, created_at: now, title: "", content: "" });
188+
189+
updateTabState(tab, {
190+
isWebMode: false,
191+
selectedMineId: newId,
192+
selectedWebIndex: null,
193+
});
194+
}, [user_id, setRow, updateTabState, tab]);
174195

175196
return (
176197
<ResourceListLayout
@@ -228,8 +249,9 @@ function ShortcutListColumn({
228249
const [showSearch, setShowSearch] = useState(false);
229250

230251
const getMineTitle = (item: UserShortcut) => {
252+
if (item.title?.trim()) return item.title;
231253
const content = item.content?.trim();
232-
if (!content) return "Empty shortcut";
254+
if (!content) return "Untitled shortcut";
233255
return content.length > 50 ? content.slice(0, 50) + "..." : content;
234256
};
235257

@@ -256,7 +278,7 @@ function ShortcutListColumn({
256278
<div className="w-full h-full flex flex-col">
257279
<div className="border-b border-neutral-200">
258280
<div className="py-2 pl-3 pr-1 flex items-center justify-between h-12">
259-
<h3 className="text-sm font-medium">Chat Shortcuts</h3>
281+
<h3 className="text-sm font-medium">Shortcuts</h3>
260282
<div className="flex items-center gap-1">
261283
<Tooltip>
262284
<TooltipTrigger asChild>

apps/desktop/src/components/main/sidebar/profile/auth.tsx

Lines changed: 11 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
11
import { LogIn, LogOut } from "lucide-react";
2-
import { useEffect, useState } from "react";
2+
import { useCallback } from "react";
33

4+
import { commands as windowsCommands } from "@hypr/plugin-windows";
45
import { Button } from "@hypr/ui/components/ui/button";
5-
import { Input } from "@hypr/ui/components/ui/input";
6-
import { cn } from "@hypr/utils";
7-
8-
import { useAuth } from "../../../../auth";
96

107
type AuthSectionProps = {
118
isAuthenticated: boolean;
12-
onSignIn: () => Promise<void> | void;
139
onSignOut: () => Promise<void> | void;
1410
};
1511

16-
export function AuthSection({
17-
isAuthenticated,
18-
onSignIn,
19-
onSignOut,
20-
}: AuthSectionProps) {
21-
const [isPending, setIsPending] = useState(false);
22-
23-
const auth = useAuth();
24-
const [devMode, setDevMode] = useState(false);
25-
const [callbackUrl, setCallbackUrl] = useState("");
26-
27-
useEffect(() => {
28-
if (isAuthenticated) {
29-
setIsPending(false);
30-
}
31-
}, [isAuthenticated]);
12+
export function AuthSection({ isAuthenticated, onSignOut }: AuthSectionProps) {
13+
const handleOpenAccount = useCallback(async () => {
14+
await windowsCommands.windowShow({ type: "settings" });
15+
await windowsCommands.windowNavigate(
16+
{ type: "settings" },
17+
"/app/settings?tab=account",
18+
);
19+
}, []);
3220

3321
if (isAuthenticated) {
3422
return (
@@ -45,104 +33,9 @@ export function AuthSection({
4533
);
4634
}
4735

48-
if (isPending) {
49-
if (devMode) {
50-
return (
51-
<div className="px-1 py-2">
52-
<div
53-
className={cn([
54-
"space-y-3",
55-
"rounded-lg border border-neutral-200",
56-
"bg-white",
57-
"p-4",
58-
])}
59-
>
60-
<div className="space-y-1">
61-
<p className="text-sm font-medium text-neutral-900">
62-
Manual callback
63-
</p>
64-
<p className="text-xs text-neutral-600">
65-
Paste the callback URL below.
66-
</p>
67-
</div>
68-
<div className="space-y-2">
69-
<Input
70-
type="text"
71-
className="text-sm"
72-
placeholder="hyprnote://auth?access_token=...&refresh_token=..."
73-
value={callbackUrl}
74-
onChange={(e) => setCallbackUrl(e.target.value)}
75-
/>
76-
<Button
77-
onClick={() => auth?.handleAuthCallback(callbackUrl)}
78-
variant="default"
79-
className="w-full"
80-
>
81-
Submit
82-
</Button>
83-
</div>
84-
</div>
85-
</div>
86-
);
87-
}
88-
89-
return (
90-
<div className="px-1 py-2">
91-
<div
92-
className={cn([
93-
"space-y-3",
94-
"rounded-lg border border-neutral-200",
95-
"bg-white",
96-
"p-4",
97-
])}
98-
>
99-
<div className="space-y-1">
100-
<p className="text-sm font-medium text-neutral-900">
101-
Not redirected?
102-
</p>
103-
<p className="text-xs text-neutral-600">
104-
Click below to reopen the sign-in page.
105-
</p>
106-
</div>
107-
<div className="space-y-1">
108-
<Button
109-
onClick={() => onSignIn()}
110-
variant="default"
111-
className="w-full"
112-
>
113-
Reopen sign-in page
114-
</Button>
115-
{import.meta.env.DEV && (
116-
<p
117-
onClick={() => setDevMode(true)}
118-
className="text-xs text-neutral-600 cursor-pointer hover:text-neutral-900"
119-
>
120-
Click here to workaround deeplink.
121-
</p>
122-
)}
123-
</div>
124-
</div>
125-
</div>
126-
);
127-
}
128-
129-
const handleStartSignIn = async () => {
130-
setIsPending(true);
131-
try {
132-
await onSignIn();
133-
} catch (error) {
134-
setIsPending(false);
135-
throw error;
136-
}
137-
};
138-
13936
return (
14037
<div className="p-1 pt-2">
141-
<Button
142-
onClick={() => handleStartSignIn()}
143-
variant="default"
144-
className="w-full"
145-
>
38+
<Button onClick={handleOpenAccount} variant="default" className="w-full">
14639
<LogIn size={16} />
14740
Sign in
14841
</Button>

apps/desktop/src/components/main/sidebar/profile/index.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ export function ProfileSection({ onExpandChange }: ProfileSectionProps = {}) {
5353
onExpandChange?.(isExpanded);
5454
}, [isExpanded, onExpandChange]);
5555

56-
const handleSignIn = useCallback(async () => {
57-
await auth?.signIn();
58-
}, [auth]);
59-
6056
const handleSignOut = useCallback(async () => {
6157
await auth?.signOut();
6258
closeMenu();
@@ -212,7 +208,6 @@ export function ProfileSection({ onExpandChange }: ProfileSectionProps = {}) {
212208

213209
<AuthSection
214210
isAuthenticated={isAuthenticated}
215-
onSignIn={handleSignIn}
216211
onSignOut={handleSignOut}
217212
/>
218213
</motion.div>

0 commit comments

Comments
 (0)