Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita880e67

Browse files
committed
feat: add badge in the navbar
1 parent72f58c0 commita880e67

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

‎site/src/components/Badge/Badge.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const badgeVariants = cva(
2424
"border border-solid border-border-destructive bg-surface-red text-highlight-red shadow",
2525
green:
2626
"border border-solid border-surface-green bg-surface-green text-highlight-green shadow",
27+
info:"border border-solid border-surface-sky bg-surface-sky text-highlight-sky shadow",
2728
},
2829
size:{
2930
xs:"text-2xs font-regular h-5 [&_svg]:hidden rounded px-1.5",

‎site/src/modules/dashboard/Navbar/NavbarView.tsx‎

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import{API}from"api/api";
22
importtype*asTypesGenfrom"api/typesGenerated";
3+
import{Badge}from"components/Badge/Badge";
34
import{Button}from"components/Button/Button";
45
import{ExternalImage}from"components/ExternalImage/ExternalImage";
56
import{CoderIcon}from"components/Icons/CoderIcon";
67
importtype{ProxyContextValue}from"contexts/ProxyContext";
78
import{useWebpushNotifications}from"contexts/useWebpushNotifications";
9+
import{useAuthenticated}from"hooks";
810
import{useEmbeddedMetadata}from"hooks/useEmbeddedMetadata";
911
import{NotificationsInbox}from"modules/notifications/NotificationsInbox/NotificationsInbox";
12+
import{data}from"pages/TasksPage/TasksPage";
1013
importtype{FC}from"react";
14+
import{useQuery}from"react-query";
1115
import{NavLink,useLocation}from"react-router";
1216
import{cn}from"utils/cn";
1317
import{DeploymentDropdown}from"./DeploymentDropdown";
@@ -144,7 +148,6 @@ interface NavItemsProps {
144148

145149
constNavItems:FC<NavItemsProps>=({ className})=>{
146150
constlocation=useLocation();
147-
const{ metadata}=useEmbeddedMetadata();
148151

149152
return(
150153
<navclassName={cn("flex items-center gap-4 h-full",className)}>
@@ -167,16 +170,56 @@ const NavItems: FC<NavItemsProps> = ({ className }) => {
167170
>
168171
Templates
169172
</NavLink>
170-
{metadata["tasks-tab-visible"].value&&(
171-
<NavLink
172-
className={({ isActive})=>{
173-
returncn(linkStyles.default,isActive ?linkStyles.active :"");
174-
}}
175-
to="/tasks"
173+
<TasksNavItem/>
174+
</nav>
175+
);
176+
};
177+
178+
constTasksNavItem:FC=()=>{
179+
const{ metadata}=useEmbeddedMetadata();
180+
constcanSeeTasks=
181+
!!metadata["tasks-tab-visible"].value||
182+
process.env.NODE_ENV==="development";
183+
const{ user}=useAuthenticated();
184+
constfilter={
185+
user:{
186+
label:user.username,
187+
value:user.username,
188+
avatarUrl:user.avatar_url,
189+
},
190+
};
191+
const{data:idleTasks}=useQuery({
192+
queryKey:["tasks",filter],
193+
queryFn:()=>data.fetchTasks(filter),
194+
refetchInterval:10_000,
195+
enabled:canSeeTasks,
196+
refetchOnWindowFocus:true,
197+
select:(data)=>
198+
data.filter((task)=>task.workspace.latest_app_status?.state==="idle"),
199+
});
200+
201+
if(!canSeeTasks){
202+
returnnull;
203+
}
204+
205+
return(
206+
<NavLink
207+
className={({ isActive})=>{
208+
returncn(linkStyles.default,isActive ?linkStyles.active :"");
209+
}}
210+
to="/tasks"
211+
>
212+
Tasks
213+
{idleTasks&&idleTasks.length>0&&(
214+
<Badge
215+
variant="info"
216+
size="xs"
217+
className="ml-2"
218+
aria-label={`You have${idleTasks.length} tasks waiting for input`}
176219
>
177-
Tasks
178-
</NavLink>
220+
{idleTasks.length}
221+
</Badge>
179222
)}
180-
</nav>
223+
</NavLink>
181224
);
182225
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp