Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test("list latest packages", async () => {
owner_github_username: "user1",
creator_account_id: "creator1",
created_at: "2023-01-01T00:00:00Z",
owner_tscircuit_handle: "user1",
updated_at: "2023-01-01T00:00:00Z",
description: "Description 1",
ai_description: "AI Description 1",
Expand All @@ -28,6 +29,7 @@ test("list latest packages", async () => {
owner_github_username: "user2",
creator_account_id: "creator2",
created_at: "2023-01-02T00:00:00Z",
owner_tscircuit_handle: "user2",
updated_at: "2023-01-02T00:00:00Z",
description: "Description 2",
ai_description: "AI Description 2",
Expand All @@ -44,6 +46,7 @@ test("list latest packages", async () => {
owner_github_username: "user3",
creator_account_id: "creator3",
created_at: "2023-01-03T00:00:00Z",
owner_tscircuit_handle: "user3",
updated_at: "2023-01-03T00:00:00Z",
description: "Description 3",
ai_description: "AI Description 3",
Expand All @@ -61,6 +64,7 @@ test("list latest packages", async () => {
owner_github_username: "user4",
creator_account_id: "creator4",
created_at: "2023-01-04T00:00:00Z",
owner_tscircuit_handle: "user4",
updated_at: "2023-01-04T00:00:00Z",
description: "Snippet Description",
ai_description: "AI Description",
Expand Down
21 changes: 13 additions & 8 deletions fake-snippets-api/lib/db/db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
> & {
creator_account_id?: string
github_repo_full_name?: string
owner_org_id?: string
branch_name?: string
commit_message?: string
commit_author?: string
Expand All @@ -362,7 +363,7 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
const newPackage = {
package_id: `pkg_${nextId}`,
creator_account_id: snippet.creator_account_id ?? snippet.owner_name, // Using owner_name as account_id since we don't have context
owner_org_id: "", // Empty string instead of null to match type
owner_org_id: snippet.owner_org_id ?? "",
owner_github_username: snippet.owner_name,
is_source_from_github: false,
description: snippet.description || "",
Expand Down Expand Up @@ -1162,7 +1163,7 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
return false
}
return (
account.github_username.toLowerCase().includes(lowercaseQuery) ||
account.github_username?.toLowerCase().includes(lowercaseQuery) ||
(account.tscircuit_handle?.toLowerCase().includes(lowercaseQuery) ??
false)
)
Expand Down Expand Up @@ -1362,12 +1363,13 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
_package: Omit<
z.input<typeof packageSchema>,
"package_id" | "github_repo_full_name"
>,
> & {
github_repo_full_name?: string | null
},
): Package => {
const timestamp = Date.now()
const newPackage = {
package_id: `package_${timestamp}`,
github_repo_full_name: null,
latest_pcb_preview_image_url:
_package.latest_pcb_preview_image_url ??
`/api/packages/images/${_package.name}`,
Expand All @@ -1377,6 +1379,7 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
latest_sch_preview_image_url:
_package.latest_sch_preview_image_url ??
`/api/packages/images/${_package.name}`,
github_repo_full_name: _package.github_repo_full_name ?? null,
..._package,
}
set((state) => ({
Expand Down Expand Up @@ -1711,7 +1714,6 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
},
auth?: { account_id?: string },
) => {
console.log(filters)
let orgs = get().organizations
if (filters?.owner_account_id) {
orgs = orgs.filter(
Expand All @@ -1727,9 +1729,12 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
})
}
if (filters?.tscircuit_handle) {
orgs = orgs.filter(
(org) => org.tscircuit_handle === filters.tscircuit_handle,
)
orgs = orgs.filter((org) => {
const account = get().accounts.find(
(account) => account.account_id === org.owner_account_id,
)
return account?.tscircuit_handle === filters.tscircuit_handle
})
}
if (filters?.name) {
orgs = orgs.filter(
Expand Down
2 changes: 1 addition & 1 deletion fake-snippets-api/lib/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const shippingInfoSchema = z.object({
})
export const accountSchema = z.object({
account_id: z.string(),
github_username: z.string(),
github_username: z.string().nullable(),
tscircuit_handle: z.string().nullable(),
shippingInfo: shippingInfoSchema.optional(),
personal_org_id: z.string().nullable(),
Expand Down
3 changes: 3 additions & 0 deletions fake-snippets-api/lib/db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ export default () => (
creator_account_id: account_id,
owner_org_id: "org-1234",
owner_github_username: "testuser",
github_repo_full_name: "testuser/test",
description: "A test package for development",
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
Expand Down Expand Up @@ -729,6 +730,7 @@ export const TestComponent = ({ name }: { name: string }) => (
db.addSnippet({
name: "seveibar/a555timer",
unscoped_name: "a555timer",
owner_org_id: "org-1234",
owner_name: "seveibar",
code: `
export const A555Timer = ({ name }: { name: string }) => (
Expand Down Expand Up @@ -1260,6 +1262,7 @@ exports.A555Timer = A555Timer;
name: "testuser/a555timer-square-wave",
unscoped_name: "a555timer-square-wave",
owner_name: "testuser",
owner_org_id: "org-1234",
branch_name: "main",
commit_message: "Attempted build of a555timer-square-wave package",
commit_author: "testuser",
Expand Down
2 changes: 1 addition & 1 deletion fake-snippets-api/lib/middleware/with-session-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const withSessionAuth: Middleware<
type: "session"
account_id: string
personal_org_id: string
github_username: string
github_username: string | null
tscircuit_handle: string | null
session_id: string
orgs: Array<{
Expand Down
10 changes: 8 additions & 2 deletions fake-snippets-api/routes/api/accounts/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default withRouteSpec({
auth: "session",
commonParams: z.object({
github_username: z.string().optional(),
tscircuit_handle: z.string().optional(),
}),
jsonResponse: z.object({
account: publicAccountSchema.extend({
Expand All @@ -19,8 +20,13 @@ export default withRouteSpec({
}),
})(async (req, ctx) => {
let account: Account | undefined
const { github_username } = req.commonParams
if (github_username) {
const { github_username, tscircuit_handle } = req.commonParams
if (tscircuit_handle) {
account = ctx.db.accounts.find(
(acc: Account) =>
acc.tscircuit_handle?.toLowerCase() === tscircuit_handle.toLowerCase(),
)
} else if (github_username) {
const foundAccount = ctx.db.accounts.find(
(acc: Account) =>
acc.github_username?.toLowerCase() === github_username.toLowerCase(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default withRouteSpec({
github_installation_id: githubInstallationId,
account_id: ctx.auth.account_id,
installation_id: mockInstallationId,
github_username: account.github_username,
github_username: account.github_username as string,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
is_active: true,
Expand Down
2 changes: 1 addition & 1 deletion fake-snippets-api/routes/api/orgs/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default withRouteSpec({
message: "You must provide filtering parameters",
})
}
console.log(2, github_handle, tscircuit_handle)

const orgs = ctx.db.getOrgs(
{
github_handle,
Expand Down
6 changes: 4 additions & 2 deletions fake-snippets-api/routes/api/packages/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ export default withRouteSpec({
}

if (!owner_segment) {
owner_segment = org_id ? org!.org_name : ctx.auth.github_username
owner_segment = org_id
? (org!.org_name ?? "")
: (ctx.auth.github_username ?? "")
}

const final_name = name ?? `${owner_segment}/${unscoped_name}`

const requested_owner_lower = owner_segment.toLowerCase()
const personal_owner_lower = ctx.auth.github_username.toLowerCase()
const personal_owner_lower = ctx.auth.github_username?.toLowerCase()

let owner_org_id = ctx.auth.personal_org_id
let owner_github_username = ctx.auth.github_username
Expand Down
20 changes: 20 additions & 0 deletions fake-snippets-api/routes/api/packages/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default withRouteSpec({
owner_org_id: z.string().optional(),
name: z.string().optional(),
limit: z.number().int().min(1).optional(),
starred_by: z.string().optional(),
}),
jsonResponse: z.object({
ok: z.boolean(),
Expand All @@ -34,6 +35,7 @@ export default withRouteSpec({
is_writable,
owner_org_id,
limit,
starred_by,
} = req.commonParams

const auth = "auth" in ctx && ctx.auth ? ctx.auth : null
Expand Down Expand Up @@ -81,6 +83,24 @@ export default withRouteSpec({
if (owner_org_id) {
packages = packages.filter((p) => p.owner_org_id === owner_org_id)
}
if (starred_by) {
const starredByAccount = ctx.db.accounts.find(
(acc) => acc.github_username?.toLowerCase() === starred_by.toLowerCase(),
)
if (starredByAccount) {
const starredPackageIds = new Set(
ctx.db.accountPackages
.filter(
(ap) =>
ap.account_id === starredByAccount.account_id && ap.is_starred,
)
.map((ap) => ap.package_id),
)
packages = packages.filter((p) => starredPackageIds.has(p.package_id))
} else {
packages = []
}
}
if (limit) {
packages = packages.slice(0, limit)
}
Expand Down
1 change: 1 addition & 0 deletions fake-snippets-api/routes/api/snippets/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export default withRouteSpec({

return ctx.json({
ok: true,
// @ts-expect-error depreceated snippets routes
snippet: snippetResponse,
})
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion fake-snippets-api/routes/api/snippets/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export default withRouteSpec({
if (starred_by) {
starredByAccount =
ctx.db.accounts.find(
(acc) => acc.github_username.toLowerCase() === starred_by.toLowerCase(),
(acc) =>
acc.github_username?.toLowerCase() === starred_by.toLowerCase(),
) || null

if (starredByAccount) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/CmdKMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const CmdKMenu = () => {
useImportComponentDialog()
const { importComponent: importJlcpcbComponent } = useJlcpcbComponentImport()
const session = useGlobalStore((s) => s.session)
const currentUser = session?.github_username
const currentUser = session?.tscircuit_handle
const jlcpcbProxyRequestHeaders = useMemo(
() =>
session?.token
Expand Down Expand Up @@ -198,7 +198,7 @@ const CmdKMenu = () => {
.map((account: Account) => {
const { score, matches } = fuzzyMatch(
searchQuery,
account.github_username,
account.tscircuit_handle ?? account.github_username ?? "",
)
return { ...account, score, matches }
})
Expand All @@ -213,7 +213,7 @@ const CmdKMenu = () => {
if (!currentUser) return []
try {
const response = await axios.post(`/packages/list`, {
owner_github_username: currentUser,
owner_tscircuit_handle: currentUser,
limit: 5,
})
return response.data.packages || []
Expand Down
8 changes: 6 additions & 2 deletions src/components/ProfileRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ const ProfileRouter: React.FC = () => {
return <NotFoundPage heading="Username Not Provided" />
}

if (isLoading && !isFetched) {
if (isLoading || !isFetched) {
return <FullPageLoader />
}

if (organization && !organization.is_personal_org && !error) {
if (error || !organization) {
return <NotFoundPage heading="Organization Not Found" />
}

if (!organization.is_personal_org) {
return <OrganizationProfilePageContent org={organization} />
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/UserCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const UserCard: React.FC<UserCardProps> = ({
if (onClick) {
onClick(account)
} else if (!withLink) {
window.location.href = `/${account.github_username}`
window.location.href = `/${account.tscircuit_handle}`
}
}

Expand Down Expand Up @@ -53,11 +53,11 @@ export const UserCard: React.FC<UserCardProps> = ({
<div className="flex-1 min-w-0 flex flex-col justify-center my-auto">
<div className="flex justify-between items-start">
<h2 className="text-md font-semibold truncate pr-[30px]">
<span className="text-gray-900">{account.github_username}</span>
<span className="text-gray-900">{account.tscircuit_handle}</span>
</h2>
</div>
<p className="text-sm text-gray-500 truncate max-w-xs">
@{account.github_username}
@{account.tscircuit_handle}
</p>
</div>
</div>
Expand All @@ -67,8 +67,8 @@ export const UserCard: React.FC<UserCardProps> = ({
if (withLink) {
return (
<Link
key={account.github_username}
href={`/${account.github_username}`}
key={account.tscircuit_handle}
href={`/${account.tscircuit_handle}`}
onClick={onClick ? () => onClick(account) : undefined}
>
{cardContent}
Expand Down
22 changes: 12 additions & 10 deletions src/components/organization/OrganizationMembers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,37 @@ export const OrganizationMembers: React.FC<OrganizationMembersProps> = ({
return (
<Link
key={member.account_id || member.github_username}
href={`/${member.github_username}`}
href={`/${member.github_username || member.account_id}`}
className="block"
>
<div className="flex items-center justify-between p-3 rounded-lg hover:bg-gray-50 transition-colors cursor-pointer">
<div className="flex items-center gap-3 min-w-0 flex-1">
<Avatar className="h-10 w-10 sm:h-12 sm:w-12 flex-shrink-0">
<AvatarImage
src={`https://github.com/${member.github_username}.png`}
alt={`${member.github_username} avatar`}
src={`https://github.com/${member.github_username || "unknown"}.png`}
alt={`${member.github_username || "User"} avatar`}
/>
<AvatarFallback className="text-sm font-medium">
{member.github_username
.split(" ")
.map((word) => word[0])
.join("")
.toUpperCase()
.slice(0, 2)}
? member.github_username
.split(" ")
.map((word) => word[0])
.join("")
.toUpperCase()
.slice(0, 2)
: "U"}
</AvatarFallback>
</Avatar>

<div className="min-w-0 flex-1">
<div className="flex items-center gap-2 mb-1">
<h3 className="font-medium text-gray-900 truncate">
{member.github_username}
{member.github_username || "Unknown User"}
</h3>
<RoleBadge role={role} />
</div>
<p className="text-sm text-gray-500 truncate">
@{member.github_username}
@{member.github_username || "unknown"}
</p>
</div>
</div>
Expand Down
Loading