-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathheader.tsx
More file actions
148 lines (134 loc) · 4.37 KB
/
header.tsx
File metadata and controls
148 lines (134 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"use client"
import React from 'react'
import Image from 'next/image'
import { useCalendarToggle } from './calendar-toggle-context'
import { ModeToggle } from './mode-toggle'
import { cn } from '@/lib/utils'
import HistoryContainer from './history-container'
import { Button } from '@/components/ui/button'
import {
Search,
CircleUserRound,
Map,
CalendarDays,
TentTree
} from 'lucide-react'
import { MapToggle } from './map-toggle'
import { ProfileToggle } from './profile-toggle'
import { PurchaseCreditsPopup } from './purchase-credits-popup'
import { useUsageToggle } from './usage-toggle-context'
import { useProfileToggle } from './profile-toggle-context'
import { useHistoryToggle } from './history-toggle-context'
import { useState, useEffect } from 'react'
import {
Tooltip,
TooltipContent,
TooltipTrigger
} from '@/components/ui/tooltip'
export const Header = () => {
const { toggleCalendar } = useCalendarToggle()
const [isPurchaseOpen, setIsPurchaseOpen] = useState(false)
const { toggleUsage, isUsageOpen } = useUsageToggle()
const { activeView, closeProfileView } = useProfileToggle()
const { toggleHistory } = useHistoryToggle()
const handleUsageToggle = () => {
// If we're about to open usage and profile is open, close profile first
if (!isUsageOpen && activeView) {
closeProfileView()
}
toggleUsage()
}
useEffect(() => {
// Open payment popup as soon as application opens
setIsPurchaseOpen(true)
}, [])
return (
<>
<PurchaseCreditsPopup isOpen={isPurchaseOpen} onClose={() => setIsPurchaseOpen(false)} />
<header className="fixed w-full p-1 md:p-2 flex justify-between items-center z-[60] backdrop-blur bg-background/95 border-b border-border/40">
<div>
<a href="/">
<span className="sr-only">Chat</span>
</a>
</div>
<div className="absolute left-1 flex items-center">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
onClick={toggleHistory}
data-testid="logo-history-toggle"
aria-label="Toggle history"
>
<Image
src="/images/logo.svg"
alt="Logo"
width={20}
height={20}
className="h-5 w-auto"
/>
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">Toggle history</TooltipContent>
</Tooltip>
<h1 className="text-2xl font-poppins font-semibold text-primary">
QCX
</h1>
</div>
<div className="flex-1 hidden md:flex justify-center gap-10 items-center z-10">
<ProfileToggle/>
<MapToggle />
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
onClick={toggleCalendar}
data-testid="calendar-toggle"
aria-label="Open calendar"
>
<CalendarDays className="h-[1.2rem] w-[1.2rem]" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">Open calendar</TooltipContent>
</Tooltip>
<div id="header-search-portal" className="contents" />
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
onClick={handleUsageToggle}
aria-label="Open usage"
>
<TentTree className="h-[1.2rem] w-[1.2rem]" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">Open usage</TooltipContent>
</Tooltip>
<ModeToggle />
<HistoryContainer location="header" />
</div>
{/* Mobile menu buttons */}
<div className="flex md:hidden gap-2">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
onClick={handleUsageToggle}
aria-label="Open usage"
>
<TentTree className="h-[1.2rem] w-[1.2rem]" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">Open usage</TooltipContent>
</Tooltip>
<ProfileToggle/>
</div>
</header>
</>
)
}
export default Header