forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
284 lines (272 loc) · 12.1 KB
/
Copy pathpage.tsx
File metadata and controls
284 lines (272 loc) · 12.1 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
'use client';
import React, { useState } from "react";
import { AlertTriangle, RefreshCw } from "lucide-react";
import { Layout } from "@/components/Layout";
import { Sidebar } from "@/components/SideBar/Sidebar";
import { RightPanel } from "@/components/RightPanel/RightPanel";
import { AuthModal } from "@/components/AuthModal/AuthModal";
import { EntranceAnimation } from "@/components/EntranceAnimation";
import { useAppStore, appStore } from "@/lib/store";
import { RequestType, TeamMember } from "@/types";
// Import your feature components
import { Dashboard } from "@/features/Dashboard";
import { RPCBuilder } from "@/features/RPCBuilder";
import { PTBBuilder } from "@/features/PTBBuilder";
import { HistoryFeature } from "@/features/History";
import { NewRequestPage } from "@/features/NewRequestPage";
import { ProfilePage } from "@/features/ProfilePage";
import { SettingsPage } from "@/features/SettingsPage";
import { AIChat } from "@/features/AIChat";
import { CollectionRunner } from "@/features/CollectionRunner";
import { ContractBuilder } from "@/features/ContractBuilder";
import { Playground } from "@/features/Playground";
import { WorkspaceOnboarding } from "@/features/WorkspaceOnboarding";
import { DocsPage } from "@/features/DocsPage";
import { EcosystemPage } from "@/features/EcosystemPage";
import { FeaturesPage } from "@/features/FeaturesPage";
import { IntegrationsPage } from "@/features/IntegrationsPage";
import { InfrastructurePage } from "@/features/InfrastructurePage";
import { PartnersPage } from "@/features/PartnersPage";
import { NewCollectionPage } from "@/features/NewCollectionPage";
const MOCK_TEAM: TeamMember[] = [];
const WorkspaceContent: React.FC = () => {
const { tabs, activeTabId } = useAppStore();
const activeTab = tabs.find(t => t.id === activeTabId);
if (!activeTabId || !activeTab) {
return <Dashboard />;
}
switch (activeTab.type) {
case 'dashboard':
return <Dashboard />;
case 'rpc':
return <RPCBuilder />;
case 'ptb':
return <PTBBuilder />;
case 'history':
return <HistoryFeature />;
case 'settings':
return <SettingsPage />;
case 'profile':
return <ProfilePage />;
case 'ai_chat':
return <AIChat />;
case 'new_request':
return <NewRequestPage tabId={activeTab.id} initialData={activeTab.data} />;
case 'runner':
return <CollectionRunner collectionId={activeTab.data?.collectionId} />;
case 'move':
return <ContractBuilder />;
case 'playground':
return <Playground />;
case 'docs':
return <DocsPage embedded />;
case 'ecosystem':
return <EcosystemPage embedded />;
case 'features':
return <FeaturesPage embedded />;
case 'integrations':
return <IntegrationsPage embedded />;
case 'infrastructure':
return <InfrastructurePage embedded />;
case 'partners':
return <PartnersPage embedded />;
case 'new_collection':
return <NewCollectionPage tabId={activeTab.id} />;
default:
return <Dashboard />;
}
};
export default function WorkspacePage() {
const {
tabs,
activeTabId,
workspaces,
currentWorkspaceId,
hasHydratedWorkspaces,
workspacesLoadFailed,
collections,
history,
envVariables,
isAuthModalOpen,
user,
activityLogs,
comments,
network,
} = useAppStore();
const [showEntrance, setShowEntrance] = useState(true);
const currentWorkspace =
workspaces.find((w) => w.id === currentWorkspaceId) || workspaces[0];
// Only route into onboarding when we've confirmed the account has zero
// workspaces. A failed/timed-out fetch also leaves workspaces empty, but
// routing that through onboarding would let the user "create" a
// workspace they may already have, every time the backend hiccups.
const needsWorkspaceSetup =
Boolean(user) &&
hasHydratedWorkspaces &&
!workspacesLoadFailed &&
workspaces.length === 0;
const workspacesFailedToLoad =
Boolean(user) &&
hasHydratedWorkspaces &&
workspacesLoadFailed &&
workspaces.length === 0;
const isBootstrappingWorkspace =
Boolean(user) &&
!hasHydratedWorkspaces;
return (
<>
{showEntrance && (
<EntranceAnimation
onComplete={() => setShowEntrance(false)}
/>
)}
<div
className={`transition-opacity duration-1000 ${
showEntrance ? "opacity-0" : "opacity-100"
}`}
>
{isBootstrappingWorkspace ? (
<div className="min-h-screen bg-near-black text-white flex items-center justify-center px-6">
<div className="w-full max-w-md rounded-[2rem] border border-white/10 bg-white/[0.035] p-8 text-center shadow-[0_30px_80px_-55px_rgba(163,163,163,0.65)]">
<div className="mx-auto flex h-14 w-14 items-center justify-center rounded-[1.25rem] bg-electric-violet/10 text-electric-violet">
<div className="h-6 w-6 rounded-full border-2 border-electric-violet/30 border-t-electric-violet animate-spin" />
</div>
<h2 className="mt-5 text-2xl font-bold text-white">
Loading workspace state
</h2>
<p className="mt-3 text-sm leading-7 text-slate-400">
Restoring your txio environment, workspace list,
and saved operational context.
</p>
</div>
</div>
) : workspacesFailedToLoad ? (
<div className="min-h-screen bg-near-black text-white flex items-center justify-center px-6">
<div className="w-full max-w-md rounded-[2rem] border border-white/10 bg-white/[0.035] p-8 text-center shadow-[0_30px_80px_-55px_rgba(163,163,163,0.65)]">
<div className="mx-auto flex h-14 w-14 items-center justify-center rounded-[1.25rem] bg-red-500/10 text-red-400">
<AlertTriangle size={22} />
</div>
<h2 className="mt-5 text-2xl font-bold text-white">
Couldn't load your workspaces
</h2>
<p className="mt-3 text-sm leading-7 text-slate-400">
The server didn't respond in time. If it was
idle, it may still be waking up.
</p>
<button
onClick={() => {
appStore
.fetchWorkspaces()
.catch(() => {
// Failure already lands in
// state (workspacesLoadFailed,
// or a session reset if the
// token was invalid) — nothing
// further to do with the
// rejection here.
});
}}
className="mt-6 inline-flex items-center gap-2 rounded-2xl bg-electric-violet px-5 py-3 text-sm font-bold text-white transition-all hover:bg-soft-purple"
>
<RefreshCw size={15} />
Try again
</button>
</div>
</div>
) : needsWorkspaceSetup ? (
user ? (
<WorkspaceOnboarding
user={user}
onCreateWorkspace={
appStore.createWorkspace
}
/>
) : null
) : currentWorkspace ? (
<Layout
sidebar={
<Sidebar
currentWorkspace={currentWorkspace}
workspaces={workspaces}
collections={collections}
history={history}
envVariables={envVariables}
activeTabId={activeTabId}
onSwitchWorkspace={
appStore.setWorkspace
}
onSelectRequest={(req) =>
appStore.openTab(
req.type === RequestType.RPC
? "rpc"
: "ptb",
req
)
}
onSelectCollectionRequest={(node) => {
if (node.requestData) {
appStore.openTab(
node.requestData.type === RequestType.RPC
? "rpc"
: "ptb",
node.requestData
);
}
}}
onNewRequest={() =>
appStore.openTab("new_request")
}
onUpdateEnv={appStore.updateEnv}
onToggleExpand={appStore.toggleCollectionExpand}
onCreateCollection={appStore.createCollection}
onCreateWorkspace={appStore.createWorkspace}
/>
}
workspace={<WorkspaceContent />}
inspector={
<RightPanel
network={network}
activityLogs={activityLogs}
comments={
activeTabId
? comments[activeTabId] || []
: []
}
activeRequestId={activeTabId || ""}
onPostComment={(content) =>
activeTabId &&
appStore.postComment(
activeTabId,
content
)
}
onClose={() =>
appStore.toggleInspector()
}
/>
}
tabs={tabs}
activeTabId={activeTabId || undefined}
onSelectTab={appStore.setActiveTab}
onCloseTab={appStore.closeTab}
onRenameTab={appStore.renameTab}
onNewTab={() =>
appStore.openTab("new_request")
}
/>
) : null}
</div>
<AuthModal
isOpen={isAuthModalOpen}
onClose={() =>
appStore.setAuthModal(false)
}
user={user}
onLogin={appStore.login}
onSignup={appStore.signup}
onLogout={appStore.logout}
teamMembers={MOCK_TEAM}
/>
</>
);
}