Skip to content

Commit 28ea887

Browse files
committed
refactor: Filter and display only relevant teams, remove debug log, and un-hardcode checkbox state.
1 parent 096e2e5 commit 28ea887

4 files changed

Lines changed: 8 additions & 76 deletions

File tree

api/auth.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ export async function handleGoogleCallback(
100100
// Verify and decode the ID token
101101
await verifyGoogleToken(tokens.id_token)
102102
const userInfo = decodeGoogleJWT(tokens.id_token) as GoogleUserInfo
103-
if (userInfo.picture) {
104-
userInfo.picture = await savePicture(userInfo.picture)
105-
}
103+
userInfo.picture &&= await savePicture(userInfo.picture)
106104
const sessionId = await authenticateOauthUser(userInfo)
107105

108106
// Return response with session cookie

api/lmdb-store.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { STORE_SECRET, STORE_URL } from '/api/lib/env.ts'
22

33
const headers = { authorization: `Bearer ${STORE_SECRET}` }
4-
export const pending = new Set<Promise<unknown>>()
5-
export const sync = () => Promise.all([...pending])
64
export const getOne = async <T>(
75
path: string,
86
id: string,
@@ -13,17 +11,6 @@ export const getOne = async <T>(
1311
return res.json()
1412
}
1513

16-
export const set = (path: string, id: unknown, dt: unknown) => {
17-
const body = typeof dt === 'string' ? dt : JSON.stringify(dt)
18-
const p = fetch(
19-
`${STORE_URL}/${path}/${encodeURIComponent(String(id))}`,
20-
{ method: 'POST', body, headers },
21-
)
22-
pending.add(p)
23-
p.finally(() => pending.delete(p))
24-
return 1
25-
}
26-
2714
export const get = async <T>(
2815
path: string,
2916
params?: { q?: string; limit?: number; from?: number },

tasks/seed.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,8 @@ import {
33
DeploymentsCollection,
44
type Project,
55
ProjectsCollection,
6-
type User,
7-
UsersCollection,
86
} from '/api/schema.ts'
97

10-
const users: User[] = [
11-
{
12-
userEmail: 'admin@example.com',
13-
userFullName: 'Admin User',
14-
userPicture: undefined,
15-
isAdmin: true,
16-
},
17-
{
18-
userEmail: 'member1@example.com',
19-
userFullName: 'Member One',
20-
userPicture: undefined,
21-
isAdmin: false,
22-
},
23-
{
24-
userEmail: 'member2@example.com',
25-
userFullName: 'Member Two',
26-
userPicture: undefined,
27-
isAdmin: false,
28-
},
29-
{
30-
userEmail: 'clement@01talent.com',
31-
userFullName: 'Clement',
32-
userPicture: undefined,
33-
isAdmin: true,
34-
},
35-
{
36-
userEmail: 'abdou.top@01talent.com',
37-
userFullName: 'Abdou Top',
38-
userPicture: undefined,
39-
isAdmin: true,
40-
},
41-
]
42-
438
const projects: Omit<Project, 'createdAt'>[] = [
449
{
4510
slug: 'website-redesign',
@@ -66,7 +31,6 @@ const projects: Omit<Project, 'createdAt'>[] = [
6631

6732
async function clearCollection(
6833
collection:
69-
| typeof UsersCollection
7034
| typeof ProjectsCollection
7135
| typeof DeploymentsCollection,
7236
) {
@@ -81,17 +45,9 @@ async function seed() {
8145
console.log('Starting seeding process...')
8246

8347
// Clear existing data
84-
await clearCollection(UsersCollection)
8548
await clearCollection(ProjectsCollection)
8649
await clearCollection(DeploymentsCollection)
8750

88-
// Seed users
89-
console.log('Seeding users...')
90-
for (const user of users) {
91-
await UsersCollection.insert(user)
92-
}
93-
console.log('Users seeded.')
94-
9551
// Seed projects
9652
console.log('Seeding projects...')
9753
for (const [_, project] of projects.entries()) {

web/pages/ProjectsPage.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ const ProjectCard = (
123123
{ project, members }: { project: Project; members: string[] },
124124
) => {
125125
const isMember = members.includes(user.data?.id || '')
126-
console.log(members, user.data?.id, isMember)
127126
return (
128127
<A
129128
key={project.slug}
@@ -187,7 +186,6 @@ const TeamMembersRow = ({ user }: { user: Team['members'][number] }) => (
187186
<input
188187
type='checkbox'
189188
class='toggle toggle-sm toggle-primary'
190-
checked={true}
191189
// onChange={(e) => {
192190
// if ((e.target as HTMLInputElement).checked) {
193191
// addUserToTeam(user, team)
@@ -569,19 +567,12 @@ export function ProjectsPage() {
569567
? ''
570568
: 'pointer-events-none cursor-not-allowed opacity-20'
571569

572-
const hasTeams = teams.data && teams.data.length > 0
573-
const sortedTeams = teams.data?.sort((a, b) => {
574-
const aHasUser = a.members.includes(user.data?.id || '')
575-
const bHasUser = b.members.includes(user.data?.id || '')
576-
const aProjects = projectsByTeam[a.id] ?? []
577-
const bProjects = projectsByTeam[b.id] ?? []
578-
if (aHasUser && !bHasUser) return -1
579-
if (!aHasUser && bHasUser) return 1
580-
if (aProjects.length > bProjects.length) return -1
581-
if (aProjects.length < bProjects.length) return 1
582-
return 0
583-
}) ?? []
584-
570+
const sortedTeams =
571+
teams.data?.filter((t) =>
572+
(t.members.includes(user.data?.id || '') || isAdmin) &&
573+
projectsByTeam[t.id]?.length > 0
574+
) ?? []
575+
585576
return (
586577
<PageLayout>
587578
<PageHeader>
@@ -617,7 +608,7 @@ export function ProjectsPage() {
617608
</PageHeader>
618609

619610
<PageContent>
620-
{!hasTeams
611+
{sortedTeams.length === 0
621612
? (
622613
<EmptyState
623614
icon={Search}

0 commit comments

Comments
 (0)