Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: browse ssr improvements, supabase db types #102

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Vercel Preview URL Lighthouse Audit

on:
issue_comment:
types: [edited]
pull_request

jobs:
generate_lighthouse_audit:
Expand Down
15 changes: 13 additions & 2 deletions apps/masterbots.ai/app/(browse)/[category]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BrowseList from '@/components/browse/browse-list'
import { BrowseCategoryTabs } from '@/components/browse/browse-category-tabs'
import { BrowseSearchInput } from '@/components/browse/browse-search-input'
import { getCategories } from '@/services/hasura'
import { getBrowseThreads, getCategories } from '@/services/hasura'

export const revalidate = 3600 // revalidate the data at most every hour

Expand All @@ -11,6 +11,17 @@ export default async function BrowseCategoryPage({
params: { category: string }
}) {
const categories = await getCategories()
const categoryId = categories.find(
c =>
c.name.toLowerCase().replace(/\s+/g, '_').replace(/\&/g, 'n') ===
params.category
).categoryId
if (!categoryId) throw new Error('Category id not foud')

const threads = await getBrowseThreads({
limit: 50,
categoryId
})

return (
<div className="w-full max-w-screen-lg pb-10 mx-auto">
Expand All @@ -19,7 +30,7 @@ export default async function BrowseCategoryPage({
initialCategory={params.category}
/>
<BrowseSearchInput />
<BrowseList />
<BrowseList initialThreads={threads} />
</div>
)
}
2 changes: 0 additions & 2 deletions apps/masterbots.ai/app/(browse)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ interface BrowseLayoutProps {
export default async function BrowseLayout({ children }: BrowseLayoutProps) {
return (
<BrowseProvider>
{/* TODO: https://github.com/TheSGJ/nextjs-toploader/issues/66 */}
{/* <NextTopLoader color="#1ED761" initialPosition={0.20} /> */}
<main className="flex flex-col h-[calc(100vh-theme(spacing.16))]">
<section className="overflow-auto group scrollbar w-full">
{children}
Expand Down
7 changes: 5 additions & 2 deletions apps/masterbots.ai/app/(browse)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import BrowseList from '@/components/browse/browse-list'
import { BrowseCategoryTabs } from '@/components/browse/browse-category-tabs'
import { BrowseSearchInput } from '@/components/browse/browse-search-input'
import { getCategories } from '@/services/hasura'
import { getBrowseThreads, getCategories } from '@/services/hasura'

export const revalidate = 3600 // revalidate the data at most every hour

export default async function BrowsePage() {
const categories = await getCategories()
const threads = await getBrowseThreads({
limit: 50
})

return (
<div className="w-full max-w-screen-lg px-4 pb-10 mx-auto">
<BrowseCategoryTabs categories={categories} />
<BrowseSearchInput />
<BrowseList />
<BrowseList initialThreads={threads} />
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { motion } from 'framer-motion'
import type { Category } from '@repo/mb-genql'
import Link from 'next/link'

export function BrowseCategoryButton({
export function BrowseCategoryLink({
category,
activeTab,
onClick,
Expand Down
8 changes: 4 additions & 4 deletions apps/masterbots.ai/components/browse/browse-category-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { Category } from '@repo/mb-genql'
import { useEffect } from 'react'
import { useBrowse } from '@/hooks/use-browse'
import { BrowseCategoryButton } from './browse-category-button'
import { BrowseCategoryLink } from './browse-category-link'

export function BrowseCategoryTabs({
categories,
Expand Down Expand Up @@ -45,8 +45,8 @@ export function BrowseCategoryTabs({
}, [initialCategory])

return (
<div className="w-full py-[10px] my-3 !overflow-x-auto overflow-y-hidden whitespace-nowrap scrollbar small-thumb">
<BrowseCategoryButton
<div className="w-full py-[10px] my-3 !overflow-x-auto overflow-y-hidden whitespace-nowrap scrollbar small-thumb justify-between flex">
<BrowseCategoryLink
activeTab={activeTab}
category="all"
id="browse-category-tab__null"
Expand All @@ -55,7 +55,7 @@ export function BrowseCategoryTabs({
}}
/>
{categories.map((category, key) => (
<BrowseCategoryButton
<BrowseCategoryLink
activeTab={activeTab}
category={category}
id={`browse-category-tab__${category.categoryId}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Link from 'next/link'
import React from 'react'
import { cn, createMessagePairs } from '@/lib/utils'
import { IconUser } from '@/components/ui/icons'
import { ChatAccordion } from '../c/chat-accordion'
import { ChatAccordion } from '../shared/chat-accordion'
import type { MessagePair } from './browse-chat-messages'
import { convertMessage } from './browse-chat-messages'
import { BrowseChatMessage } from './browse-chat-message'
Expand Down
2 changes: 1 addition & 1 deletion apps/masterbots.ai/components/browse/browse-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation'
import React from 'react'
import { cn, sleep } from '@/lib/utils'
import { getMessages } from '@/services/hasura'
import { ChatAccordion } from '../c/chat-accordion'
import { ChatAccordion } from '../shared/chat-accordion'
import { ShortMessage } from '../short-message'
import { IconOpenAI, IconUser } from '../ui/icons'
import { BrowseChatMessageList } from './browse-chat-message-list'
Expand Down
28 changes: 9 additions & 19 deletions apps/masterbots.ai/components/browse/browse-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@ import BrowseListItem from './browse-list-item'

const PAGE_SIZE = 50

export default function BrowseList() {
export default function BrowseList({ initialThreads }: BrowseListProps) {
const { keyword, tab } = useBrowse()

const [threads, setThreads] = React.useState<Thread[]>([])
const [filteredThreads, setFilteredThreads] = React.useState<Thread[]>([])
const [threads, setThreads] = React.useState<Thread[]>(initialThreads)
const [filteredThreads, setFilteredThreads] =
React.useState<Thread[]>(initialThreads)
const [loading, setLoading] = React.useState<boolean>(false)
const [count, setCount] = React.useState<number>(0)

const fetchThreads = async (keyword: string, tab: number | null) => {
const threads = await getBrowseThreads({
categoryId: tab,
keyword,
limit: PAGE_SIZE
})
setThreads(threads)
setCount(threads.length)
}
const [count, setCount] = React.useState<number>(initialThreads.length)

const verifyKeyword = () => {
if (!keyword) {
Expand Down Expand Up @@ -61,10 +51,6 @@ export default function BrowseList() {
setLoading(false)
}

React.useEffect(() => {
fetchThreads('', tab)
}, [tab])

React.useEffect(() => {
verifyKeyword()
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -85,3 +71,7 @@ export default function BrowseList() {
</div>
)
}

type BrowseListProps = {
initialThreads: Thread[]
}
2 changes: 1 addition & 1 deletion apps/masterbots.ai/components/browse/browse-thread.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import type { Thread } from '@repo/mb-genql'
import { cn, extractBetweenMarkers } from '@/lib/utils'
import { cn } from '@/lib/utils'
import { BrowseChatMessages } from './browse-chat-messages'

export function BrowseThread({
Expand Down
2 changes: 1 addition & 1 deletion apps/masterbots.ai/components/c/chat-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChatMessage } from '@/components/c/chat-message'
import { cn, createMessagePairs } from '@/lib/utils'
import { useThread } from '@/hooks/use-thread'
import { ShortMessage } from '../short-message'
import { ChatAccordion } from './chat-accordion'
import { ChatAccordion } from '../shared/chat-accordion'

export interface ChatList {
messages: Message[]
Expand Down
2 changes: 1 addition & 1 deletion apps/masterbots.ai/components/c/thread-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useThread } from '@/hooks/use-thread'
import { useSidebar } from '@/hooks/use-sidebar'
import { cn, sleep } from '@/lib/utils'
import { ShortMessage } from '../short-message'
import { ChatAccordion } from './chat-accordion'
import { ChatAccordion } from '../shared/chat-accordion'
import { ChatList } from './chat-list'

export default function ThreadList({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,16 @@ export function ChatAccordion({
}, [activeThread, thread])

React.useEffect(() => {
if (isOpen !== undefined) {
setOpen(isOpen)
}
if (isOpen !== undefined) setOpen(isOpen)
}, [isOpen])

const toggle = () => {
const newState = !open
setOpen(newState)
if (!newState && handleOpen) {
handleOpen()
}
if (thread.threadId) {
setActiveThread(newState ? thread : null)
}
if (!newState && handleOpen) handleOpen()
if (thread.threadId) setActiveThread(newState ? thread : null)
if (isNewResponse) setIsNewResponse(false)
if (onToggle) {
onToggle(newState)
}
if (onToggle) onToggle(newState)
}

return (
Expand Down Expand Up @@ -120,3 +112,16 @@ export function ChatAccordion({
</div>
)
}

// ;<Dialog>
// <DialogTrigger>Open</DialogTrigger>
// <DialogContent>
// <DialogHeader>
// <DialogTitle>Are you absolutely sure?</DialogTitle>
// <DialogDescription>
// This action cannot be undone. This will permanently delete your account
// and remove your data from our servers.
// </DialogDescription>
// </DialogHeader>
// </DialogContent>
// </Dialog>
3 changes: 2 additions & 1 deletion apps/masterbots.ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"preview": "next build && next start",
"type-check": "tsc --noEmit",
"format:write": "prettier --write \"{app,lib,components}/**/*.{ts,tsx,mdx}\" --cache",
"format:check": "prettier --check \"{app,lib,components}**/*.{ts,tsx,mdx}\" --cache"
"format:check": "prettier --check \"{app,lib,components}**/*.{ts,tsx,mdx}\" --cache",
"types": "supabase gen types typescript --project-id ipgwcdekxoxsjojvzrre > services/supabase/database.types.ts"
},
"dependencies": {
"@blockmatic/hooks-utils": "^3.0.0",
Expand Down
Loading
Loading