Skip to content

Commit

Permalink
[optimize] simplify Simple Scroll List components
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Jul 11, 2023
1 parent 44c9bda commit c3760db
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 203 deletions.
20 changes: 2 additions & 18 deletions components/Activity/ActivityLogList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { observer } from 'mobx-react';
import { ScrollListProps } from 'mobx-restful-table';
import { Badge, ListGroup } from 'react-bootstrap';

import { Log, LogModel } from '../../models/Log';
import { XScrollList, XScrollListProps } from '../layout/ScrollList';

export interface ActivityLogListProps extends XScrollListProps<Log> {
export interface ActivityLogListProps extends ScrollListProps<Log> {
store: LogModel;
}

Expand All @@ -24,18 +23,3 @@ export const ActivityLogListLayout = ({
))}
</ListGroup>
);

@observer
export class ActivityLogList extends XScrollList<ActivityLogListProps> {
store = this.props.store;

constructor(props: ActivityLogListProps) {
super(props);

this.boot();
}

renderList() {
return <ActivityLogListLayout defaultData={this.store.allItems} />;
}
}
61 changes: 24 additions & 37 deletions components/Git/List.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
import { observer } from 'mobx-react';
import { ScrollListProps } from 'mobx-restful-table';
import { FC } from 'react';
import { Col, Row } from 'react-bootstrap';

import { GitTemplate, GitTemplateModal } from '../../models/TemplateRepo';
import { XScrollList, XScrollListProps } from '../layout/ScrollList';
import { GitTemplate } from '../../models/TemplateRepo';
import { GitCard, GitCardProps } from './Card';

export interface GitListProps
extends XScrollListProps<GitTemplate>,
Pick<GitCardProps, 'renderController'> {
store: GitTemplateModal;
}
export type GitListLayoutProps = Pick<
ScrollListProps<GitTemplate>,
'defaultData'
> &
Pick<GitCardProps, 'renderController'>;

@observer
export class GitList extends XScrollList<GitListProps> {
store = this.props.store;

constructor(props: GitListProps) {
super(props);

this.boot();
}

renderList() {
const { renderController } = this.props,
{ allItems } = this.store;

return (
<Row as="ul" className="list-unstyled g-4" xs={1} sm={2}>
{allItems.map(item => (
<Col as="li" key={item.id}>
<GitCard
className="h-100 shadow-sm"
{...item}
renderController={renderController}
/>
</Col>
))}
</Row>
);
}
}
export const GitListLayout: FC<GitListLayoutProps> = ({
defaultData,
renderController,
}) => (
<Row as="ul" className="list-unstyled g-4" xs={1} sm={2}>
{defaultData?.map(item => (
<Col as="li" key={item.id}>
<GitCard
className="h-100 shadow-sm"
{...item}
renderController={renderController}
/>
</Col>
))}
</Row>
);
61 changes: 24 additions & 37 deletions components/Git/TeamGitList.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
import { observer } from 'mobx-react';
import { ScrollListProps } from 'mobx-restful-table';
import { FC } from 'react';
import { Col, Row } from 'react-bootstrap';

import { GitModel, GitRepository } from '../../models/Git';
import { XScrollList, XScrollListProps } from '../layout/ScrollList';
import { GitRepository } from '../../models/Git';
import { GitTeamCard, GitTeamCardProps } from './GitTeamCard';

export interface GitListProps
extends XScrollListProps<GitRepository>,
Pick<GitTeamCardProps, 'renderController'> {
store: GitModel;
}
export type TeamGitListLayoutProps = Pick<
ScrollListProps<GitRepository>,
'defaultData'
> &
Pick<GitTeamCardProps, 'renderController'>;

@observer
export class TeamGitList extends XScrollList<GitListProps> {
store = this.props.store;

constructor(props: GitListProps) {
super(props);

this.boot();
}

renderList() {
const { renderController } = this.props,
{ allItems } = this.store;

return (
<Row as="ul" className="list-unstyled g-4" xs={1} sm={2}>
{allItems.map(item => (
<Col as="li" key={item.id}>
<GitTeamCard
className="h-100 shadow-sm"
{...item}
renderController={renderController}
/>
</Col>
))}
</Row>
);
}
}
export const TeamGitListLayout: FC<TeamGitListLayoutProps> = ({
defaultData,
renderController,
}) => (
<Row as="ul" className="list-unstyled g-4" xs={1} sm={2}>
{defaultData?.map(item => (
<Col as="li" key={item.id}>
<GitTeamCard
className="h-100 shadow-sm"
{...item}
renderController={renderController}
/>
</Col>
))}
</Row>
);
15 changes: 0 additions & 15 deletions components/Organization/OrganizationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ export const OrganizationListLayout = ({
</ul>
);

@observer
export class OrganizationList extends XScrollList<OrganizationListProps> {
store = this.props.store;

constructor(props: OrganizationListProps) {
super(props);

this.boot();
}

renderList() {
return <OrganizationListLayout defaultData={this.store.allItems} />;
}
}

export const OrganizationTableLayout = ({
defaultData = [],
selectedIds = [],
Expand Down
20 changes: 2 additions & 18 deletions components/Team/TeamList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { observer } from 'mobx-react';
import { ScrollListProps } from 'mobx-restful-table';
import { Col, Row } from 'react-bootstrap';

import { Team, TeamModel } from '../../models/Team';
import { XScrollList, XScrollListProps } from '../layout/ScrollList';
import { TeamCard } from './TeamCard';

export interface TeamListProps extends XScrollListProps<Team> {
export interface TeamListProps extends ScrollListProps<Team> {
store: TeamModel;
}

Expand All @@ -20,18 +19,3 @@ export const TeamListLayout = ({
))}
</Row>
);

@observer
export class TeamList extends XScrollList<TeamListProps> {
store = this.props.store;

constructor(props: TeamListProps) {
super(props);

this.boot();
}

renderList() {
return <TeamListLayout defaultData={this.store.allItems} />;
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"array-unique-proposal": "^0.3.4",
"classnames": "^2.3.2",
"echarts-jsx": "^0.5.0",
"idea-react": "^1.0.0-rc.3",
"idea-react": "^1.0.0-rc.5",
"koajax": "^0.8.4",
"leaflet": "^1.9.4",
"leaflet.chinatmsproviders": "^3.0.6",
Expand All @@ -32,7 +32,7 @@
"mobx-i18n": "^0.3.15",
"mobx-react": "^6.3.1",
"mobx-restful": "^0.6.5",
"mobx-restful-table": "^0.11.0",
"mobx-restful-table": "^1.0.4",
"next": "^12.3.4",
"react": "^17.0.2",
"react-bootstrap": "^2.8.0",
Expand Down
11 changes: 9 additions & 2 deletions pages/activity/[name]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Loading } from 'idea-react';
import { computed, observable } from 'mobx';
import { textJoin } from 'mobx-i18n';
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import dynamic from 'next/dynamic';
import { PureComponent } from 'react';
Expand All @@ -31,7 +32,7 @@ import { MessageList } from '../../../components/Message/MessageList';
import { OrganizationListLayout } from '../../../components/Organization/OrganizationList';
import { TeamCard } from '../../../components/Team/TeamCard';
import { TeamCreateModal } from '../../../components/Team/TeamCreateModal';
import { TeamList } from '../../../components/Team/TeamList';
import { TeamListLayout } from '../../../components/Team/TeamList';
import activityStore, {
Activity,
ActivityModel,
Expand Down Expand Up @@ -318,7 +319,13 @@ export default class ActivityPage extends PureComponent<
)}
<hr />
<h3>{t('all_teams')}</h3>
<TeamList store={this.teamStore} />
<ScrollList
translator={i18n}
store={this.teamStore}
renderList={allItems => (
<TeamListLayout defaultData={allItems} />
)}
/>
</Tab>
</Tabs>
</Col>
Expand Down
11 changes: 9 additions & 2 deletions pages/activity/[name]/manage/log.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { PureComponent } from 'react';

import { ActivityLogList } from '../../../../components/Activity/ActivityLogList';
import { ActivityLogListLayout } from '../../../../components/Activity/ActivityLogList';
import { ActivityManageFrame } from '../../../../components/Activity/ActivityManageFrame';
import activityStore from '../../../../models/Activity';
import { i18n } from '../../../../models/Translation';
Expand All @@ -27,7 +28,13 @@ export default class LogPage extends PureComponent<
name={params!.name}
title={t('log')}
>
<ActivityLogList store={this.store} />
<ScrollList
translator={i18n}
store={this.store}
renderList={allItems => (
<ActivityLogListLayout defaultData={allItems} />
)}
/>
</ActivityManageFrame>
);
}
Expand Down
9 changes: 7 additions & 2 deletions pages/activity/[name]/manage/team.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { FormEvent, PureComponent } from 'react';
import {
Expand All @@ -11,7 +12,7 @@ import {
import { formToJSON } from 'web-utility';

import { ActivityManageFrame } from '../../../../components/Activity/ActivityManageFrame';
import { TeamList } from '../../../../components/Team/TeamList';
import { TeamListLayout } from '../../../../components/Team/TeamList';
import activityStore from '../../../../models/Activity';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';
Expand Down Expand Up @@ -62,7 +63,11 @@ export default class TeamManagePage extends PureComponent<
</Dropdown.Item>
</DropdownButton>
</header>
<TeamList store={this.store} />
<ScrollList
translator={i18n}
store={this.store}
renderList={allItems => <TeamListLayout defaultData={allItems} />}
/>
</Container>
</ActivityManageFrame>
);
Expand Down
27 changes: 19 additions & 8 deletions pages/activity/[name]/team/[tid]/manage/git.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { action, observable } from 'mobx';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { FormEvent, PureComponent } from 'react';
import {
Expand All @@ -12,10 +13,10 @@ import {
} from 'react-bootstrap';
import { buildURLData, formToJSON } from 'web-utility';

import { GitList } from '../../../../../../components/Git/List';
import { GitListLayout } from '../../../../../../components/Git/List';
import {
GitListProps,
TeamGitList,
TeamGitListLayout,
TeamGitListLayoutProps,
} from '../../../../../../components/Git/TeamGitList';
import { TeamManageFrame } from '../../../../../../components/Team/TeamManageFrame';
import activityStore from '../../../../../../models/Activity';
Expand Down Expand Up @@ -103,13 +104,17 @@ export default class GitPage extends PureComponent<
{t('create')}
</Button>
</div>
<GitList store={this.gitTemplateStore} />
<ScrollList
translator={i18n}
store={this.gitTemplateStore}
renderList={allItems => <GitListLayout defaultData={allItems} />}
/>
</Modal.Body>
</Modal>
);
}

renderController: GitListProps['renderController'] = ({
renderController: TeamGitListLayoutProps['renderController'] = ({
id,
name,
default_branch,
Expand Down Expand Up @@ -176,9 +181,15 @@ export default class GitPage extends PureComponent<
</Button>
</header>

<TeamGitList
<ScrollList
translator={i18n}
store={this.workspaceStore}
renderController={this.renderController}
renderList={allItems => (
<TeamGitListLayout
defaultData={allItems}
renderController={this.renderController}
/>
)}
/>
</Container>

Expand Down
Loading

0 comments on commit c3760db

Please sign in to comment.