Skip to content

Commit de6b800

Browse files
authored
Fix observations from Jun (#353)
* update * fix: update * fix: added empty state * fix: rm favourt and added card empty state * fix: hide sibe category without threads on user profile * fix: update * fix: update
1 parent 9446bb0 commit de6b800

File tree

8 files changed

+94
-34
lines changed

8 files changed

+94
-34
lines changed

apps/hasura/metadata/databases/masterbots/tables/public_chatbot.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ select_permissions:
7878
- description
7979
- name
8080
filter: {}
81+
allow_aggregations: true
8182
comment: ""
8283
- role: moderator
8384
permission:

apps/hasura/metadata/databases/masterbots/tables/public_thread.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ select_permissions:
7777
- updated_at
7878
- user_id
7979
filter: {}
80+
allow_aggregations: true
8081
comment: ""
8182
- role: moderator
8283
permission:

apps/masterbots.ai/components/layout/sidebar/sidebar-category-general.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useSidebar } from '@/lib/hooks/use-sidebar'
66
export function SidebarCategoryGeneral({ page }: { page?: string }) {
77
const { filteredCategories, isFilterMode } = useSidebar()
88

9+
910
if (!filteredCategories.length) return <div className="p-4 text-center">No matching categories found</div>
1011
return (
1112
<ul className="space-y-2">
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
import { FolderX } from 'lucide-react'
3+
4+
export function EmptyState() {
5+
return (
6+
<div className="flex flex-col justify-center items-center h-full w-full text-center p-6">
7+
<div className="mb-6">
8+
<FolderX className="mx-auto text-gray-400" size={100} strokeWidth={1} />
9+
</div>
10+
<h2 className="text-2xl font-bold text-gray-800 mb-3">
11+
No Data Available
12+
</h2>
13+
<p className="text-gray-600 max-w-md">
14+
There is no data available for this user.
15+
</p>
16+
</div>
17+
);
18+
}

apps/masterbots.ai/components/routes/profile/user-card.tsx

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { userFollowOrUnfollow } from '@/services/hasura/hasura.service'
2525
import type { SocialFollowing } from 'mb-genql'
2626
import router from 'next/router'
2727
import { useSonner } from '@/lib/hooks/useSonner'
28+
import { EmptyState } from './empty-state'
2829

2930
interface UserCardProps {
3031
user: User | null
@@ -277,20 +278,25 @@ export function UserCard({ user, loading }: UserCardProps) {
277278
<Loader className="w-16 h-16 text-white" />
278279
</div>
279280
)}
280-
{!loading && user && (
281+
{user && (
281282
<div className="relative w-full">
282283
<div className="space-y-1 ">
283284
{/* Profile Name */}
284285
<div className="px-5 pb-2 pt-7">
285286
<h2 className="text-xl font-semibold capitalize md:text-2xl">
286287
{user?.username}
287288
</h2>
288-
<div className="flex items-center space-x-1 md:hidden">
289-
<BotIcon className="w-4 h-4" />
290-
<span className="">Threads:</span>
291-
<span className="text-gray-500">{user?.threads.length}</span>
292-
</div>
293-
<div className="flex items-center space-x-1">
289+
{
290+
user?.threads.length > 0 && (
291+
<div className="items-center space-x-1 md:hidden flex">
292+
<BotIcon className="w-4 h-4" />
293+
<span className="">Threads:</span>
294+
<span className="text-gray-500">{user?.threads.length}</span>
295+
</div>
296+
)
297+
}
298+
299+
<div className="flex items-center space-x-1">
294300
<BookUser className="w-4 h-4" />
295301
<p className="text-sm ">bio:</p>
296302

@@ -338,15 +344,19 @@ export function UserCard({ user, loading }: UserCardProps) {
338344
</div>
339345

340346
{/* Stats Section */}
341-
<div className="flex flex-col p-6 md:flex-row md:justify-between">
342-
<div className="pt-5 space-y-1">
343-
<div className="items-center hidden space-x-1 md:flex">
344-
<BotIcon className="w-4 h-4" />
345-
<span className="">Threads:</span>
346-
<span className="text-gray-500">{user?.threads.length}</span>
347-
</div>
347+
<div className="flex md:flex-row flex-col md:justify-between p-6">
348+
<div className="space-y-1 pt-5">
349+
{
350+
user?.threads.length > 0 && (
351+
<div className="md:flex items-center space-x-1 hidden">
352+
<BotIcon className="w-4 h-4" />
353+
<span className="">Threads:</span>
354+
<span className="text-gray-500">{user?.threads.length}</span>
355+
</div>
356+
)
357+
}
348358

349-
<div>
359+
{/* <div>
350360
<div className="flex items-center space-x-1">
351361
<MessageSquareHeart className="w-4 h-4" />
352362
<p className="">Favourite topic:</p>
@@ -391,7 +401,7 @@ export function UserCard({ user, loading }: UserCardProps) {
391401
{favouriteTopic}
392402
</p>
393403
)}
394-
</div>
404+
</div> */}
395405
</div>
396406

397407
<div className="flex flex-col items-center space-y-3 md:mt-0 mt-7">
@@ -487,6 +497,9 @@ export function UserCard({ user, loading }: UserCardProps) {
487497
</div>
488498
</div>
489499
)}
500+
{!user && <EmptyState />}
501+
502+
490503
</div>
491504
)
492505
}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
'use client'
2-
import UserThreadPanel from "../thread/user-thread-panel";
3-
import { Thread, User } from "mb-genql";
2+
import UserThreadPanel from '../thread/user-thread-panel'
3+
import { Thread, User } from 'mb-genql'
44

5-
export function UserThreadList({ user, threads }: { user: User, threads: Thread[] }) {
6-
7-
if (!user) return null
8-
return (
9-
<div className="max-w-screen-lg pb-10 mx-auto w-full">
10-
<UserThreadPanel threads={threads} page="profile" />
11-
</div>
12-
)
13-
}
5+
export function UserThreadList({
6+
user,
7+
threads
8+
}: {
9+
user: User
10+
threads: Thread[]
11+
}) {
12+
if (!user) return null
13+
return (
14+
<div className="max-w-screen-lg pb-10 mx-auto w-full overflow-y-auto scrollbar-hide">
15+
<UserThreadPanel threads={threads} page="profile" />
16+
</div>
17+
)
18+
}

apps/masterbots.ai/lib/hooks/use-sidebar.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use client'
22

3-
import { getCategories } from '@/services/hasura'
3+
import { getCategories, getUserBySlug } from '@/services/hasura'
44
import { Category, Chatbot } from 'mb-genql'
55
import { toSlug } from 'mb-lib'
6-
import { usePathname } from 'next/navigation'
6+
import { usePathname, useParams } from 'next/navigation'
77
import * as React from 'react'
88
import { useAsync } from 'react-use'
99

@@ -65,8 +65,21 @@ interface SidebarProviderProps {
6565
export function SidebarProvider({ children }: SidebarProviderProps) {
6666
const [selectedCategories, setSelectedCategories] = React.useState<number[]>([])
6767
const [selectedChatbots, setSelectedChatbots] = React.useState<number[]>([])
68+
const { slug } = useParams()
69+
const pathname = usePathname()
70+
6871
const { value: categories, loading, error } = useAsync(async () => {
69-
const categories = await getCategories()
72+
let categories = []
73+
if(slug){
74+
const { user, error } = await getUserBySlug({
75+
slug: slug as string,
76+
isSameUser: false
77+
});
78+
const userId = user ? user?.userId : undefined
79+
categories = await getCategories(userId)
80+
}else{
81+
categories = await getCategories()
82+
}
7083
const categoriesObj = {
7184
categoriesChatbots: categories || [],
7285
categoriesId: categories.map(category => category.categoryId),
@@ -76,7 +89,8 @@ export function SidebarProvider({ children }: SidebarProviderProps) {
7689
setSelectedCategories(categoriesObj.categoriesId)
7790
setSelectedChatbots(categoriesObj.chatbotsId)
7891
return categoriesObj
79-
}, [])
92+
}, [pathname])
93+
8094
const [isSidebarOpen, setSidebarOpen] = React.useState(false)
8195
const [isLoading, setLoading] = React.useState(true)
8296
const [activeChatbot, setActiveChatbot] = React.useState<Chatbot | null>(null)
@@ -105,7 +119,6 @@ export function SidebarProvider({ children }: SidebarProviderProps) {
105119
})
106120
}
107121

108-
const pathname = usePathname()
109122
React.useEffect(() => {
110123
if (!pathname || !categories) return
111124
const pathParts = pathname.split('/')

apps/masterbots.ai/services/hasura/hasura.service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function getHasuraClient({ jwt, adminSecret }: GetHasuraClientParams) {
4242
})
4343
}
4444

45-
export async function getCategories() {
45+
export async function getCategories(userId?: string) {
4646
const client = getHasuraClient({})
4747
const { category } = await client.query({
4848
category: {
@@ -59,7 +59,15 @@ export async function getCategories() {
5959
},
6060
...everything,
6161
__args: {
62-
limit: 20,
62+
where: userId ? {
63+
chatbots: {
64+
chatbot: {
65+
threads: {
66+
userId: { _eq: userId }
67+
}
68+
}
69+
}
70+
} : {},
6371
},
6472
},
6573
})

0 commit comments

Comments
 (0)