Skip to content

Commit e7d9c95

Browse files
CopilotTechQuery
andcommitted
Refactor team page: remove manual filtering and improve code quality
- Removed manual Person filtering since MemberModel query already filters by project - Updated to use Member data directly instead of fetching all People - Destructured fields in callback functions for cleaner code - Used Card body shorthand for simpler markup - Removed unused imports (Person, PersonModel, LarkImage) - Display member info from Member table (person name, summary, githubAccount) Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
1 parent ab6d52e commit e7d9c95

1 file changed

Lines changed: 42 additions & 68 deletions

File tree

pages/hackathon/[id]/team/[tid].tsx

Lines changed: 42 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import { FC, useContext } from 'react';
55
import { Badge, Card, Col, Container, Row, Tab, Tabs } from 'react-bootstrap';
66

77
import { CommentBox } from '../../../../components/Activity/CommentBox';
8-
import { LarkImage } from '../../../../components/LarkImage';
98
import { PageHead } from '../../../../components/Layout/PageHead';
109
import { Activity, ActivityModel } from '../../../../models/Activity';
1110
import {
1211
Member,
1312
MemberModel,
14-
Person,
15-
PersonModel,
1613
Product,
1714
ProductModel,
1815
Project,
@@ -39,16 +36,6 @@ export const getServerSideProps = compose<{ id: string; tid: string }>(
3936
status: 'approved',
4037
});
4138

42-
// Get person details for members
43-
const personModel = new PersonModel(appId, tableIdMap.Person);
44-
const allPeople = await personModel.getAll();
45-
46-
// Filter team members from all people based on member records
47-
const memberPersonNames = members.map((m) => m.person as string);
48-
const teamMembers = allPeople.filter((person) =>
49-
memberPersonNames.includes(person.name as string),
50-
);
51-
5239
// Get products for this project
5340
const products = await new ProductModel(appId, tableIdMap.Product).getAll({
5441
project: team.name as string,
@@ -58,7 +45,6 @@ export const getServerSideProps = compose<{ id: string; tid: string }>(
5845
props: {
5946
activity,
6047
team,
61-
teamMembers,
6248
members,
6349
products,
6450
},
@@ -69,12 +55,11 @@ export const getServerSideProps = compose<{ id: string; tid: string }>(
6955
interface TeamPageProps {
7056
activity: Activity;
7157
team: Project;
72-
teamMembers: Person[];
7358
members: Member[];
7459
products: Product[];
7560
}
7661

77-
const TeamPage: FC<TeamPageProps> = observer(({ activity, team, teamMembers, products }) => {
62+
const TeamPage: FC<TeamPageProps> = observer(({ activity, team, members, products }) => {
7863
const { t } = useContext(I18nContext);
7964

8065
const { name: activityName } = activity;
@@ -124,28 +109,21 @@ const TeamPage: FC<TeamPageProps> = observer(({ activity, team, teamMembers, pro
124109
👥 {t('team_members')}
125110
</h2>
126111
<ul className="list-unstyled">
127-
{teamMembers.map((member) => (
128-
<li key={member.id as string} className="mb-3">
129-
<div className="d-flex align-items-center">
130-
<LarkImage
131-
src={member.avatar}
132-
alt={member.name as string}
133-
className="rounded-circle me-2"
134-
style={{ width: '40px', height: '40px' }}
135-
/>
136-
<div>
137-
<div className="fw-bold">{member.name as string}</div>
138-
{member.githubLink && (
139-
<a
140-
href={member.githubLink as string}
141-
target="_blank"
142-
rel="noreferrer"
143-
className="text-muted small"
144-
>
145-
{t('view_github')}
146-
</a>
147-
)}
148-
</div>
112+
{members.map(({ id, person, summary, githubAccount }) => (
113+
<li key={id as string} className="mb-3">
114+
<div>
115+
<div className="fw-bold">{person as string}</div>
116+
{summary && <p className="text-muted small mb-1">{summary as string}</p>}
117+
{githubAccount && (
118+
<a
119+
href={`https://github.com/${githubAccount}`}
120+
target="_blank"
121+
rel="noreferrer"
122+
className="text-muted small"
123+
>
124+
@{githubAccount as string}
125+
</a>
126+
)}
149127
</div>
150128
</li>
151129
))}
@@ -162,37 +140,33 @@ const TeamPage: FC<TeamPageProps> = observer(({ activity, team, teamMembers, pro
162140
<div className="mt-3">
163141
{products && products.length > 0 ? (
164142
<ul className="list-unstyled">
165-
{products.map((product) => (
166-
<li key={product.id as string} className="mb-3">
167-
<Card>
168-
<Card.Body>
169-
<h5>{product.name as string}</h5>
170-
{product.summary && (
171-
<p className="text-muted">{product.summary as string}</p>
143+
{products.map(({ id, name, summary, link, sourceLink }) => (
144+
<li key={id as string} className="mb-3">
145+
<Card body>
146+
<h5>{name as string}</h5>
147+
{summary && <p className="text-muted">{summary as string}</p>}
148+
<div className="d-flex gap-2 mt-2">
149+
{link && (
150+
<a
151+
href={link as string}
152+
target="_blank"
153+
rel="noreferrer"
154+
className="btn btn-sm btn-outline-primary"
155+
>
156+
{t('preview')}
157+
</a>
158+
)}
159+
{sourceLink && (
160+
<a
161+
href={sourceLink as string}
162+
target="_blank"
163+
rel="noreferrer"
164+
className="btn btn-sm btn-outline-secondary"
165+
>
166+
{t('source_code')}
167+
</a>
172168
)}
173-
<div className="d-flex gap-2 mt-2">
174-
{product.link && (
175-
<a
176-
href={product.link as string}
177-
target="_blank"
178-
rel="noreferrer"
179-
className="btn btn-sm btn-outline-primary"
180-
>
181-
{t('preview')}
182-
</a>
183-
)}
184-
{product.sourceLink && (
185-
<a
186-
href={product.sourceLink as string}
187-
target="_blank"
188-
rel="noreferrer"
189-
className="btn btn-sm btn-outline-secondary"
190-
>
191-
{t('source_code')}
192-
</a>
193-
)}
194-
</div>
195-
</Card.Body>
169+
</div>
196170
</Card>
197171
</li>
198172
))}

0 commit comments

Comments
 (0)