Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
cdf2f5d7
Unverified
提交
cdf2f5d7
authored
5月 26, 2025
作者:
Will Chen
提交者:
GitHub
5月 26, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Show a loading bar when checkout is happening (#249)
上级
2bb8902b
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
65 行增加
和
2 行删除
+65
-2
ChatHeader.tsx
src/components/chat/ChatHeader.tsx
+8
-1
LoadingBar.tsx
src/components/ui/LoadingBar.tsx
+20
-0
useCheckoutVersion.ts
src/hooks/useCheckoutVersion.ts
+9
-1
appAtoms.ts
src/store/appAtoms.ts
+15
-0
globals.css
src/styles/globals.css
+13
-0
没有找到文件。
src/components/chat/ChatHeader.tsx
浏览文件 @
cdf2f5d7
...
...
@@ -26,6 +26,8 @@ import { useStreamChat } from "@/hooks/useStreamChat";
import
{
useCurrentBranch
}
from
"@/hooks/useCurrentBranch"
;
import
{
useCheckoutVersion
}
from
"@/hooks/useCheckoutVersion"
;
import
{
useRenameBranch
}
from
"@/hooks/useRenameBranch"
;
import
{
isAnyCheckoutVersionInProgressAtom
}
from
"@/store/appAtoms"
;
import
{
LoadingBar
}
from
"../ui/LoadingBar"
;
interface
ChatHeaderProps
{
isVersionPaneOpen
:
boolean
;
...
...
@@ -46,6 +48,9 @@ export function ChatHeader({
const
[
selectedChatId
,
setSelectedChatId
]
=
useAtom
(
selectedChatIdAtom
);
const
{
refreshChats
}
=
useChats
(
appId
);
const
{
isStreaming
}
=
useStreamChat
();
const
isAnyCheckoutVersionInProgress
=
useAtomValue
(
isAnyCheckoutVersionInProgressAtom
,
);
const
{
branchInfo
,
...
...
@@ -102,6 +107,7 @@ export function ChatHeader({
return
(
<
div
className=
"flex flex-col w-full @container"
>
<
LoadingBar
isVisible=
{
isAnyCheckoutVersionInProgress
}
/>
{
/* If the version pane is open, it's expected to not always be on the main branch. */
}
{
isNotMainBranch
&&
!
isVersionPaneOpen
&&
(
<
div
className=
"flex flex-col @sm:flex-row items-center justify-between px-4 py-2 bg-amber-100 dark:bg-amber-900 text-amber-800 dark:text-amber-200"
>
...
...
@@ -161,7 +167,8 @@ export function ChatHeader({
</
div
>
)
}
<
div
className=
"@container flex items-center justify-between py-1.5"
>
{
/* Why is this pt-0.5? Because the loading bar is h-1 (it always takes space) and we want the vertical spacing to be consistent.*/
}
<
div
className=
"@container flex items-center justify-between pb-1.5 pt-0.5"
>
<
div
className=
"flex items-center space-x-2"
>
<
Button
onClick=
{
handleNewChat
}
...
...
src/components/ui/LoadingBar.tsx
0 → 100644
浏览文件 @
cdf2f5d7
import
{
cn
}
from
"@/lib/utils"
;
import
React
from
"react"
;
export
const
LoadingBar
:
React
.
FC
<
{
isVisible
:
boolean
}
>
=
({
isVisible
})
=>
{
return
(
<
div
key=
"loading-bar"
className=
{
cn
(
"relative w-full h-1 bg-primary/20 overflow-hidden"
,
isVisible
?
""
:
"invisible"
,
)
}
>
<
div
className=
{
cn
(
"absolute top-0 left-0 h-full w-1/2 bg-primary animate-marquee"
,
)
}
/>
</
div
>
);
};
src/hooks/useCheckoutVersion.ts
浏览文件 @
cdf2f5d7
import
{
useMutation
,
useQueryClient
}
from
"@tanstack/react-query"
;
import
{
IpcClient
}
from
"@/ipc/ipc_client"
;
import
{
useSetAtom
}
from
"jotai"
;
import
{
activeCheckoutCounterAtom
}
from
"@/store/appAtoms"
;
interface
CheckoutVersionVariables
{
appId
:
number
;
...
...
@@ -8,6 +10,7 @@ interface CheckoutVersionVariables {
export
function
useCheckoutVersion
()
{
const
queryClient
=
useQueryClient
();
const
setActiveCheckouts
=
useSetAtom
(
activeCheckoutCounterAtom
);
const
{
isPending
:
isCheckingOutVersion
,
mutateAsync
:
checkoutVersion
}
=
useMutation
<
void
,
Error
,
CheckoutVersionVariables
>
({
...
...
@@ -17,7 +20,12 @@ export function useCheckoutVersion() {
throw
new
Error
(
"App ID is null, cannot checkout version."
);
}
const
ipcClient
=
IpcClient
.
getInstance
();
await
ipcClient
.
checkoutVersion
({
appId
,
versionId
});
setActiveCheckouts
((
prev
)
=>
prev
+
1
);
// Increment counter
try
{
await
ipcClient
.
checkoutVersion
({
appId
,
versionId
});
}
finally
{
setActiveCheckouts
((
prev
)
=>
prev
-
1
);
// Decrement counter
}
},
onSuccess
:
(
_
,
variables
)
=>
{
// Invalidate queries that depend on the current version/branch
...
...
src/store/appAtoms.ts
0 → 100644
浏览文件 @
cdf2f5d7
import
{
atom
}
from
"jotai"
;
/**
* Atom to store the number of active checkoutVersion mutations.
* This is a "primitive" atom that you will update directly.
*/
export
const
activeCheckoutCounterAtom
=
atom
(
0
);
/**
* Derived atom that is true if any checkoutVersion mutation is in progress.
* This atom is read-only and derives its state from activeCheckoutCounterAtom.
*/
export
const
isAnyCheckoutVersionInProgressAtom
=
atom
(
(
get
)
=>
get
(
activeCheckoutCounterAtom
)
>
0
,
);
src/styles/globals.css
浏览文件 @
cdf2f5d7
...
...
@@ -280,3 +280,16 @@
width
:
0
;
}
}
@keyframes
marquee
{
0
%
{
transform
:
translateX
(
-100%
);
}
100
%
{
transform
:
translateX
(
200%
);
}
}
.animate-marquee
{
animation
:
marquee
2s
linear
infinite
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论