Skip to content

Commit a590b32

Browse files
committed
wip: zen
1 parent 5f7bba1 commit a590b32

File tree

4 files changed

+38
-41
lines changed

4 files changed

+38
-41
lines changed

packages/console/app/src/component/header.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import { A, createAsync } from "@solidjs/router"
44
import { createMemo, Match, Show, Switch } from "solid-js"
55
import { createStore } from "solid-js/store"
66
import { github } from "~/lib/github"
7-
import { queryIsLoggedIn } from "~/routes/workspace/common"
87

98
export function Header(props: { zen?: boolean }) {
109
const githubData = createAsync(() => github())
11-
const isLoggedIn = createAsync(() => queryIsLoggedIn())
1210
const starCount = createMemo(() =>
1311
githubData()?.stars
1412
? new Intl.NumberFormat("en-US", {
@@ -41,7 +39,7 @@ export function Header(props: { zen?: boolean }) {
4139
<li>
4240
<Switch>
4341
<Match when={props.zen}>
44-
<a href="/auth">{isLoggedIn() ? "Workspace" : "Login"}</a>
42+
<a href="/auth">Login</a>
4543
</Match>
4644
<Match when={!props.zen}>
4745
<A href="/zen">Zen</A>
@@ -112,7 +110,7 @@ export function Header(props: { zen?: boolean }) {
112110
<li>
113111
<Switch>
114112
<Match when={props.zen}>
115-
<a href="/auth">{isLoggedIn() ? "Workspace" : "Login"}</a>
113+
<a href="/auth">Login</a>
116114
</Match>
117115
<Match when={!props.zen}>
118116
<A href="/zen">Zen</A>

packages/console/app/src/routes/auth/index.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
1-
import { Actor } from "@opencode-ai/console-core/actor.js"
2-
import { and, Database, desc, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
3-
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
4-
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
51
import { redirect } from "@solidjs/router"
62
import type { APIEvent } from "@solidjs/start/server"
7-
import { withActor } from "~/context/auth.withActor"
3+
import { getLastSeenWorkspaceID } from "../workspace/common"
84

95
export async function GET(input: APIEvent) {
106
try {
11-
const workspaceID = await withActor(async () => {
12-
const actor = Actor.assert("account")
13-
return Database.transaction(async (tx) =>
14-
tx
15-
.select({ id: WorkspaceTable.id })
16-
.from(UserTable)
17-
.innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id))
18-
.where(
19-
and(
20-
eq(UserTable.accountID, actor.properties.accountID),
21-
isNull(UserTable.timeDeleted),
22-
isNull(WorkspaceTable.timeDeleted),
23-
),
24-
)
25-
.orderBy(desc(UserTable.timeSeen))
26-
.limit(1)
27-
.then((x) => x[0]?.id),
28-
)
29-
})
7+
const workspaceID = await getLastSeenWorkspaceID()
308
return redirect(`/workspace/${workspaceID}`)
319
} catch {
3210
return redirect("/auth/authorize")

packages/console/app/src/routes/workspace/common.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { Actor } from "@opencode-ai/console-core/actor.js"
33
import { action, query } from "@solidjs/router"
44
import { withActor } from "~/context/auth.withActor"
55
import { Billing } from "@opencode-ai/console-core/billing.js"
6+
import { User } from "@opencode-ai/console-core/user.js"
7+
import { and, Database, desc, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
8+
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
9+
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
610

711
export function formatDateForTable(date: Date) {
812
const options: Intl.DateTimeFormatOptions = {
@@ -30,17 +34,28 @@ export function formatDateUTC(date: Date) {
3034
return date.toLocaleDateString("en-US", options)
3135
}
3236

33-
export const queryIsLoggedIn = query(async () => {
37+
export async function getLastSeenWorkspaceID() {
3438
"use server"
35-
return withActor(() => {
36-
try {
37-
Actor.assert("account")
38-
return true
39-
} catch {
40-
return false
41-
}
39+
return withActor(async () => {
40+
const actor = Actor.assert("account")
41+
return Database.use(async (tx) =>
42+
tx
43+
.select({ id: WorkspaceTable.id })
44+
.from(UserTable)
45+
.innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id))
46+
.where(
47+
and(
48+
eq(UserTable.accountID, actor.properties.accountID),
49+
isNull(UserTable.timeDeleted),
50+
isNull(WorkspaceTable.timeDeleted),
51+
),
52+
)
53+
.orderBy(desc(UserTable.timeSeen))
54+
.limit(1)
55+
.then((x) => x[0]?.id),
56+
)
4257
})
43-
}, "isLoggedIn.get")
58+
}
4459

4560
export const querySessionInfo = query(async (workspaceID: string) => {
4661
"use server"

packages/console/app/src/routes/zen/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "./index.css"
2-
import { createAsync } from "@solidjs/router"
2+
import { createAsync, query, redirect } from "@solidjs/router"
33
import { Title, Meta, Link } from "@solidjs/meta"
44
import { HttpHeader } from "@solidjs/start"
55
import zenLogoLight from "../../asset/zen-ornate-light.svg"
@@ -16,10 +16,16 @@ import { Faq } from "~/component/faq"
1616
import { Legal } from "~/component/legal"
1717
import { Footer } from "~/component/footer"
1818
import { Header } from "~/component/header"
19-
import { queryIsLoggedIn } from "~/routes/workspace/common"
19+
import { getLastSeenWorkspaceID } from "../workspace/common"
20+
21+
const checkLoggedIn = query(async () => {
22+
"use server"
23+
const workspaceID = await getLastSeenWorkspaceID()
24+
if (workspaceID) throw redirect(`/workspace/${workspaceID}`)
25+
}, "checkLoggedIn.get")
2026

2127
export default function Home() {
22-
const isLoggedIn = createAsync(() => queryIsLoggedIn())
28+
createAsync(() => checkLoggedIn())
2329
return (
2430
<main data-page="zen">
2531
<HttpHeader name="Cache-Control" value="public, max-age=1, s-maxage=3600, stale-while-revalidate=86400" />
@@ -105,7 +111,7 @@ export default function Home() {
105111
</div>
106112
</div>
107113
<a href="/auth">
108-
<span>{isLoggedIn() ? "Go to workspace " : "Get started with Zen "}</span>
114+
<span>Get started with Zen </span>
109115
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
110116
<path
111117
d="M6.5 12L17 12M13 16.5L17.5 12L13 7.5"

0 commit comments

Comments
 (0)