Skip to content

Commit e07c205

Browse files
committed
[optimize] update Upstream packages
[fix] some GitHub copilot bugs [remove] some Useless components
1 parent 4a83fd2 commit e07c205

File tree

16 files changed

+346
-320
lines changed

16 files changed

+346
-320
lines changed

components/LarkImage.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1+
import { TableCellValue } from 'mobx-lark';
12
import { FC } from 'react';
23
import { Image, ImageProps } from 'react-bootstrap';
34

5+
import { fileURLOf } from '../models/Base';
46
import { DefaultImage } from '../models/configuration';
57

6-
export interface SimpleImageProps extends ImageProps {
7-
src?: string;
8+
export interface LarkImageProps extends Omit<ImageProps, 'src'> {
9+
src?: TableCellValue;
810
}
911

10-
export const LarkImage: FC<SimpleImageProps> = ({
11-
src = DefaultImage,
12-
alt,
13-
...props
14-
}) => (
12+
export const LarkImage: FC<LarkImageProps> = ({ src = DefaultImage, alt, ...props }) => (
1513
<Image
1614
fluid
1715
loading="lazy"
1816
{...props}
19-
src={src || DefaultImage}
17+
src={fileURLOf(src, true)}
2018
alt={alt}
2119
onError={({ currentTarget: image }) => {
22-
if (image.src !== DefaultImage) {
23-
image.src = DefaultImage;
20+
const path = fileURLOf(src),
21+
errorURL = decodeURI(image.src);
22+
23+
if (!path) return;
24+
25+
if (errorURL.endsWith(path)) {
26+
if (!alt) image.src = DefaultImage;
27+
} else if (!errorURL.endsWith(DefaultImage)) {
28+
image.src = path;
2429
}
2530
}}
2631
/>

components/Map/index.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/Organization/Card.tsx

Lines changed: 103 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,110 @@
1-
import { FC } from 'react';
2-
import { Badge,Card } from 'react-bootstrap';
1+
import { Organization } from '@open-source-bazaar/china-ngo-database';
2+
import { Icon } from 'idea-react';
3+
import { observable } from 'mobx';
4+
import { observer } from 'mobx-react';
5+
import { ObservedComponent } from 'mobx-react-helper';
6+
import { BadgeBar } from 'mobx-restful-table';
7+
import { HTMLAttributes } from 'react';
8+
import { Button, Card, CardProps, Image } from 'react-bootstrap';
39

4-
import { Organization } from '../../models/Organization';
10+
import { i18n, I18nContext } from '../../models/Translation';
511

6-
export interface OrganizationCardProps extends Partial<Organization> {
7-
onSwitch?: (filter: { type?: string; tags?: string; city?: string }) => void;
12+
export interface OrganizationCardProps
13+
extends Pick<HTMLAttributes<HTMLDivElement>, 'className' | 'style'>,
14+
Omit<Organization, 'id'>,
15+
CardProps {
16+
onSwitch?: (filter: Partial<Pick<Organization, 'entityType' | 'coverageArea'>>) => any;
817
}
918

10-
export const OrganizationCard: FC<OrganizationCardProps> = ({
11-
name,
12-
description,
13-
type,
14-
city,
15-
website,
16-
tags
17-
}) => (
18-
<Card className="h-100">
19-
<Card.Body>
20-
<Card.Title className="h6">{name}</Card.Title>
21-
{description && (
22-
<Card.Text className="small text-muted">
23-
{description.length > 100
24-
? `${description.substring(0, 100)}...`
25-
: description}
26-
</Card.Text>
27-
)}
28-
<div className="mt-2">
29-
{city && (
30-
<Badge bg="secondary" className="me-1">
31-
{city}
32-
</Badge>
19+
@observer
20+
export class OrganizationCard extends ObservedComponent<OrganizationCardProps, typeof i18n> {
21+
static contextType = I18nContext;
22+
23+
@observable
24+
accessor showQRC = false;
25+
26+
renderIcon() {
27+
const { website, wechatPublic } = this.observedProps.internetContact || {};
28+
29+
return (
30+
<div className="d-flex justify-content-around">
31+
{/* {email && (
32+
<Button title="E-mail" size="sm" variant="warning" href={`mailto:${email}`}>
33+
<Icon name="mailbox2" />
34+
</Button>
35+
)} */}
36+
{website && (
37+
<Button title="WWW" size="sm" target="_blank" href={website}>
38+
<Icon name="globe2" />
39+
</Button>
3340
)}
34-
{type && (
35-
<Badge bg="info" className="me-1">
36-
{type}
37-
</Badge>
41+
{wechatPublic && (
42+
<Button
43+
title="WeChat"
44+
size="sm"
45+
variant="success"
46+
onClick={() => (this.showQRC = !this.showQRC)}
47+
>
48+
<Icon name="chat-fill" />
49+
</Button>
3850
)}
39-
{tags?.map(tag => (
40-
<Badge key={tag} bg="light" text="dark" className="me-1">
41-
{tag}
42-
</Badge>
43-
))}
4451
</div>
45-
{website && (
46-
<Card.Link
47-
href={website}
48-
target="_blank"
49-
className="small"
50-
>
51-
Visit Website
52-
</Card.Link>
53-
)}
54-
</Card.Body>
55-
</Card>
56-
);
52+
);
53+
}
54+
55+
render() {
56+
const { t } = this.observedContext,
57+
{ name, entityType, services, description, internetContact, onSwitch, ...props } = this.props;
58+
const { wechatPublic } = internetContact || {};
59+
60+
return (
61+
<Card
62+
{...props}
63+
style={{
64+
...props.style,
65+
contentVisibility: 'auto',
66+
containIntrinsicHeight: '36rem',
67+
}}
68+
>
69+
{/* <Card.Img
70+
variant="top"
71+
className="object-fit-contain"
72+
style={{ height: '30vh' }}
73+
src={logos}
74+
/> */}
75+
<Card.Body>
76+
<Card.Title>
77+
{name}
78+
<BadgeBar className="ms-2" list={[{ text: entityType! }]} />
79+
</Card.Title>
80+
81+
{services && (
82+
<BadgeBar
83+
className="justify-content-end"
84+
list={services.map(({ serviceCategory }) => ({ text: serviceCategory! }))}
85+
/>
86+
)}
87+
<Card.Text
88+
className="d-none d-sm-block text-wrap overflow-auto"
89+
style={{ minHeight: '5rem', maxHeight: '10rem' }}
90+
>
91+
{description}
92+
</Card.Text>
93+
</Card.Body>
94+
95+
<Card.Footer>
96+
{this.renderIcon()}
97+
98+
{this.showQRC && (
99+
<Image
100+
className="mt-2"
101+
src={`https://open.weixin.qq.com/qr/code?username=${wechatPublic}`}
102+
alt={wechatPublic}
103+
fluid
104+
/>
105+
)}
106+
</Card.Footer>
107+
</Card>
108+
);
109+
}
110+
}

components/Organization/Charts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { BarSeries, PieSeries, SVGCharts, Title, Tooltip, XAxis, YAxis } from 'e
22
import { observer } from 'mobx-react';
33
import { FC, useContext } from 'react';
44

5-
import { I18nContext } from '../../models/Translation';
65
import { OrganizationStatistic, sortStatistic } from '../../models/Organization';
6+
import { I18nContext } from '../../models/Translation';
77

88
const OrganizationCharts: FC<OrganizationStatistic> = observer(
99
({ entityType, serviceCategory, coverageArea }) => {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.groupTitle {
2+
background-color: rgb(52, 112, 159);
3+
}
4+
.listItem {
5+
transition: 0.25ms;
6+
&:hover {
7+
cursor: pointer;
8+
box-shadow: 1px 1px 5px 1px rgba(0, 0, 0, 0.2);
9+
}
10+
}

components/Organization/ChinaPublicInterestLandscape.tsx renamed to components/Organization/Landscape.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
import { Organization } from '@open-source-bazaar/china-ngo-database';
12
import { Dialog } from 'idea-react';
23
import { observable } from 'mobx';
34
import { observer } from 'mobx-react';
45
import { Component } from 'react';
5-
import { Image, Modal } from 'react-bootstrap';
6+
import { Modal } from 'react-bootstrap';
67
import { splitArray } from 'web-utility';
78

8-
import { Organization } from '@open-source-bazaar/china-ngo-database';
9-
import systemStore from '../../models/System';
109
import { OrganizationModel } from '../../models/Organization';
11-
10+
import systemStore from '../../models/System';
1211
import { OrganizationCard } from './Card';
1312
import styles from './LandScape.module.less';
1413

components/Organization/List.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

models/Organization.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ export class OrganizationModel extends Searchable<Organization & Base>(StrapiLis
6262
const serviceCategory = countBy(
6363
list,
6464
({ services }) =>
65-
services
66-
?.map(({ serviceCategory }) => serviceCategory!)
67-
.flat()
68-
.filter(Boolean) || [],
65+
services?.map(({ serviceCategory }) => serviceCategory!).filter(Boolean) || [],
6966
);
7067
return (this.statistic = { ...statistic, serviceCategory } as OrganizationStatistic);
7168
}
@@ -76,10 +73,7 @@ export class OrganizationModel extends Searchable<Organization & Base>(StrapiLis
7673
return (this.categoryMap = groupBy(
7774
allData,
7875
({ services }) =>
79-
services
80-
?.map(({ serviceCategory }) => serviceCategory!)
81-
.flat()
82-
.filter(Boolean) || [],
76+
services?.map(({ serviceCategory }) => serviceCategory!).filter(Boolean) || [],
8377
));
8478
}
8579
}

models/Translation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { loadLanguageMapFrom, parseCookie, TranslationMap, TranslationModel } from 'mobx-i18n';
1+
import { loadLanguageMapFrom, TranslationMap, TranslationModel } from 'mobx-i18n';
22
import { DataObject } from 'mobx-restful';
33
import { NextPageContext } from 'next';
44
import { createContext } from 'react';
5+
import { parseCookie } from 'web-utility';
56

67
import zhCN from '../translation/zh-CN';
78

models/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseCookie } from 'mobx-i18n';
1+
import { parseCookie } from 'web-utility';
22

33
export const isServer = () => typeof window === 'undefined';
44

0 commit comments

Comments
 (0)