Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 76ac5ee

Browse files
authored
refactor(works-card): adjust style && re-org (#1055)
* refactor(works-cards): adjust style & idea * refactor(works-cards): extract to common Cards * test(cypress): skip shortcut test * fix(ci): remove videoCount && run migration before test
1 parent 5b3821b commit 76ac5ee

File tree

22 files changed

+270
-293
lines changed

22 files changed

+270
-293
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
- name: (Backend) Install Packages
4343
working-directory: ./backend_server
4444
run: mix deps.get > /dev/null
45+
- name: (Backend) run migration
46+
working-directory: ./backend_server
47+
run: MIX_ENV=ci MIX_ENV=ci mix ecto.migrate > /dev/null
4548
- name: (Backend) set up test DB
4649
working-directory: ./backend_server
4750
run: MIX_ENV=ci mix ecto.setup > /dev/null

cypress/integration/home/layout.spec.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ describe('home page: ', () => {
3232
})
3333

3434
// TODO: modify keys not working ..
35-
it.skip('doramon Comp should close after shortcut pressed', () => {
36-
// ctrl + C pressed
37-
cy.id('header-search').click()
38-
cy.id('doraemon-inputer').should('be.visible')
39-
cy.id('doraemon-inputer').type('{ctrl}C', { release: true })
40-
cy.id('doraemon-inputer').should('not.be.visible')
41-
42-
// ctrl + G pressed
43-
cy.id('header-search').click()
44-
cy.id('doraemon-inputer').should('be.visible')
45-
cy.id('doraemon-inputer').type('{ctrl}G')
46-
cy.id('doraemon-inputer').should('not.be.visible')
47-
48-
// esc pressed
49-
cy.id('header-search').click()
50-
cy.id('doraemon-inputer').should('be.visible')
51-
cy.id('doraemon-inputer').type('{esc}')
52-
cy.id('doraemon-inputer').should('not.be.visible')
53-
})
35+
// it.skip('doramon Comp should close after shortcut pressed', () => {
36+
// // ctrl + C pressed
37+
// cy.id('header-search').click()
38+
// cy.id('doraemon-inputer').should('be.visible')
39+
// cy.id('doraemon-inputer').type('{ctrl}C', { release: true })
40+
// cy.id('doraemon-inputer').should('not.be.visible')
41+
42+
// // ctrl + G pressed
43+
// cy.id('header-search').click()
44+
// cy.id('doraemon-inputer').should('be.visible')
45+
// cy.id('doraemon-inputer').type('{ctrl}G')
46+
// cy.id('doraemon-inputer').should('not.be.visible')
47+
48+
// // esc pressed
49+
// cy.id('header-search').click()
50+
// cy.id('doraemon-inputer').should('be.visible')
51+
// cy.id('doraemon-inputer').type('{esc}')
52+
// cy.id('doraemon-inputer').should('not.be.visible')
53+
// })
5454

5555
it('user-related area should be seen', () => {
5656
cy.id('header-unlogin-user').should('be.visible')

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"test:dev": "cross-env NODE_ENV=test jest --config .jest.config.js",
2929
"test:watch": "npm run test -- --watch",
3030
"test:cover": "npm run test -- --coverage",
31-
"test:e2e": "cypress open",
31+
"test:e2e": "./node_modules/.bin/cypress open",
3232
"cy:run": "./node_modules/.bin/cypress run --key 60eb2dd7-724d-4b39-bd12-f434f3465866 --record",
3333
"cy:run:free": "./node_modules/.bin/cypress run",
3434
"test:ci": "start-server-and-test ci http://localhost:3000 cy:run:free",
@@ -153,7 +153,7 @@
153153
"bundlewatch": "^0.2.7",
154154
"commitizen": "3.1.2",
155155
"coveralls": "3.0.14",
156-
"cypress": "6.2.0",
156+
"cypress": "^7.0.0",
157157
"cz-conventional-changelog": "^3.0.0",
158158
"enzyme": "3.11.0",
159159
"enzyme-adapter-react-16": "1.15.2",

src/components/WorksCard/index.js renamed to src/components/Cards/WorksCard.tsx

+33-66
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
*/
66

77
import React from 'react'
8-
import T from 'prop-types'
98

109
import { ICON, ICON_CMD } from '@/config'
11-
import { buildLog, cutRest, nilOrEmpty } from '@/utils'
10+
import { buildLog, cutRest } from '@/utils'
1211

1312
import DigestSentence from '@/components/DigestSentence'
1413
import { SpaceGrow } from '@/components/Common'
@@ -28,36 +27,47 @@ import {
2827
TechIcon,
2928
Divider,
3029
GithubIcon,
31-
} from './styles'
30+
} from './styles/works_card'
3231

3332
/* eslint-disable-next-line */
3433
const log = buildLog('c:WorksCard:index')
3534

36-
const getSafeValue = (mode, value, defaultValue) => {
37-
return mode === 'preview' && nilOrEmpty(value) ? defaultValue : value
35+
type TProps = {
36+
testid?: string
37+
withBg?: boolean
38+
mode?: 'default' | 'preview'
39+
item: {
40+
cover: string
41+
title: string
42+
desc: string
43+
tag: {
44+
title: string
45+
}
46+
platform: {
47+
title: string
48+
}
49+
techStack: {
50+
icon: string
51+
raw: string
52+
}[]
53+
insertedAt: string
54+
upvote: number
55+
commentsCount: number
56+
isOSS: boolean
57+
ossAddr?: boolean
58+
}
3859
}
3960

40-
const WorksCard = ({
41-
withBg,
42-
testid,
43-
mode,
61+
const WorksCard: React.FC<TProps> = ({
62+
testid = 'works-card',
4463
item,
45-
defaultTitle,
46-
defaultDesc,
47-
defaultUpvote,
48-
defaultCommentsCount,
64+
withBg = false,
65+
mode = 'default',
66+
// item,
4967
}) => {
5068
const descLimit = mode === 'default' ? 30 : 20
5169

52-
const title = getSafeValue(mode, item.title, defaultTitle)
53-
const desc = getSafeValue(mode, item.desc, defaultDesc)
54-
55-
const upvote = getSafeValue(mode, item.upvote, defaultUpvote)
56-
const commentsCount = getSafeValue(
57-
mode,
58-
item.commentsCount,
59-
defaultCommentsCount,
60-
)
70+
const { title, desc, upvote, commentsCount } = item
6171

6272
return (
6373
<Wrapper testid={testid} withBg={withBg}>
@@ -71,7 +81,7 @@ const WorksCard = ({
7181
<Header>
7282
<div>
7383
<Title>{title}</Title>
74-
<DigestSentence top={5} bottom={15}>
84+
<DigestSentence top={5} bottom={15} onPreview={() => log}>
7585
{cutRest(desc, descLimit)}
7686
</DigestSentence>
7787
</div>
@@ -127,47 +137,4 @@ const WorksCard = ({
127137
)
128138
}
129139

130-
WorksCard.propTypes = {
131-
testid: T.string,
132-
withBg: T.bool,
133-
mode: T.oneOf(['default', 'preview']),
134-
item: T.shape({
135-
cover: T.string,
136-
title: T.string,
137-
desc: T.string,
138-
tag: T.shape({
139-
title: T.string,
140-
}),
141-
platform: T.shape({
142-
title: T.string,
143-
}),
144-
techStack: T.arrayOf(
145-
T.shape({
146-
icon: T.string,
147-
}),
148-
),
149-
insertedAt: T.string,
150-
upvote: T.number,
151-
commentsCount: T.number,
152-
isOSS: T.bool,
153-
ossAddr: T.bool,
154-
}).isRequired,
155-
156-
defaultTitle: T.string,
157-
defaultDesc: T.string,
158-
defaultUpvote: T.number,
159-
defaultCommentsCount: T.number,
160-
}
161-
162-
WorksCard.defaultProps = {
163-
testid: 'works-card',
164-
withBg: false,
165-
mode: 'default',
166-
defaultTitle: '作品名称',
167-
defaultDesc: '作品简介',
168-
defaultUpvote: 99,
169-
defaultCommentsCount: 66,
170-
// item,
171-
}
172-
173140
export default React.memo(WorksCard)

src/components/WorksCard/styles/index.ts renamed to src/components/Cards/styles/works_card.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@ export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
1414
height: 118px;
1515
width: 100%;
1616
padding: 6px 20px;
17-
padding-right: 25px;
18-
border-radius: 8px;
17+
padding-right: 15px;
18+
border-radius: 3px;
1919
2020
border-bottom: 1px solid;
2121
border-bottom-color: #0b3b4a;
22+
border-left: 1px solid transparent;
23+
border-right: 1px solid transparent;
2224
2325
:last-child {
2426
border-bottom: none;
2527
}
26-
transition: all 0.25s;
28+
29+
&:hover {
30+
background: #0d3440;
31+
border-left-color: #0b3b4a;
32+
border-right-color: #0b3b4a;
33+
}
34+
transition: all 0.1s;
2735
`
2836
export const IntroImg = styled(Img)`
2937
${css.size(70)};

src/components/CommunityStatesPad/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ const CommunityStatesPad = ({
3636
editorsCount,
3737
subscribersCount,
3838
postsCount,
39-
videosCount,
4039
reposCount,
4140
jobsCount,
4241
viewerHasSubscribed,
4342
} = community
4443
const { isMobile } = useDevice()
4544

46-
const contentsCount = postsCount + videosCount + reposCount + jobsCount
45+
const contentsCount = postsCount + reposCount + jobsCount
4746

4847
return (
4948
<Wrapper>
@@ -89,7 +88,6 @@ CommunityStatesPad.propTypes = {
8988
subscribersCount: T.number,
9089
editorsCount: T.number,
9190
postsCount: T.number,
92-
videosCount: T.number,
9391
reposCount: T.number,
9492
jobsCount: T.number,
9593
viewerHasSubscribed: T.bool,
@@ -104,7 +102,6 @@ CommunityStatesPad.defaultProps = {
104102
subscribersCount: 0,
105103
editorsCount: 0,
106104
postsCount: 0,
107-
videosCount: 0,
108105
reposCount: 0,
109106
jobsCount: 0,
110107
viewerHasSubscribed: false,

src/components/WorksCard/tests/index.test.ts

-10
This file was deleted.

src/containers/content/WorksContent/Brand.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import { Wrapper, Title, Desc } from './styles/brand'
3+
import { Wrapper, Title, Desc, Divider } from './styles/brand'
44

55
type TProps = {
66
testid?: string
@@ -11,6 +11,7 @@ const Brand: React.FC<TProps> = ({ testid = 'works-content-brand' }) => {
1111
<Wrapper testid={testid}>
1212
<Title>作品集市</Title>
1313
<Desc>by makers, for makers.</Desc>
14+
<Divider />
1415
</Wrapper>
1516
)
1617
}

src/containers/content/WorksContent/FilterBar.tsx

+8-25
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,39 @@ import React from 'react'
33
import { mockNaviCatalogMenu } from '@/utils'
44

55
import { Br } from '@/components/Common'
6-
import { OrButton } from '@/components/Buttons'
7-
import FiltersMenu from '@/components/FiltersMenu'
6+
// import FiltersMenu from '@/components/FiltersMenu'
87
import NaviCatalog from '@/components/NaviCatalog'
98

10-
import { VIEW } from './constant'
9+
// import { VIEW } from './constant'
1110

12-
import fakeFilterItems from './fakeFilterItems'
11+
// import fakeFilterItems from './fakeFilterItems'
1312
import { Wrapper, FilterWrapper } from './styles/filter_bar'
1413

15-
import { changeView } from './logic'
14+
// import { changeView } from './logic'
1615

1716
type TProps = {
18-
activeView: string
17+
activeView?: string
1918
}
2019

2120
const FilterBar: React.FC<TProps> = ({ activeView }) => {
2221
return (
2322
<Wrapper>
24-
<OrButton
25-
size="small"
26-
activeKey={activeView}
27-
group={[
28-
{
29-
key: VIEW.WORKS,
30-
title: '作品',
31-
},
32-
{
33-
key: VIEW.MILESTONE,
34-
title: '动态', // 里面再成 里程碑,和讨论
35-
},
36-
]}
37-
onClick={changeView}
38-
/>
39-
<Br bottom={30} />
4023
<FilterWrapper>
4124
<NaviCatalog
4225
title="类别筛选"
4326
withDivider={false}
4427
items={mockNaviCatalogMenu()}
4528
/>
4629
</FilterWrapper>
47-
<Br bottom={40} />
48-
<FilterWrapper>
30+
{/* <Br bottom={40} /> */}
31+
{/* <FilterWrapper>
4932
<FiltersMenu
5033
title="高级搜索"
5134
items={fakeFilterItems}
5235
withDivider
5336
revert
5437
/>
55-
</FilterWrapper>
38+
</FilterWrapper> */}
5639
</Wrapper>
5740
)
5841
}

0 commit comments

Comments
 (0)