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

Commit c2c06c9

Browse files
authored
refactor(publish-button): add menu option (#1329)
1 parent 2389349 commit c2c06c9

File tree

12 files changed

+101
-8
lines changed

12 files changed

+101
-8
lines changed

src/containers/thread/ThreadSidebar/ClassicLayout/DynamicPart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const ClassicLayout: FC<TProps> = ({
8686
<PublishButton
8787
thread={thread}
8888
community={community.raw}
89-
text="反馈/建议/问题"
89+
text="参与讨论"
9090
/>
9191
) : (
9292
<NoteWrapper>

src/containers/thread/ThreadSidebar/styles/classic_layout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export const CommunityNoteWrapper = styled.div`
5252
`
5353
export const PublishWrapper = styled.div<TActive>`
5454
display: ${({ show }) => (show ? 'block' : 'none')};
55-
width: 160px;
56-
max-width: 180px;
55+
width: 185px;
56+
max-width: 185px;
5757
`
5858
export const NoteWrapper = styled.div`
5959
color: ${theme('thread.articleDigest')};

src/spec/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export type {
8282
TTagMode,
8383
TMenuOption,
8484
TToastOption,
85+
TPublishMode,
8586
} from './utils'
8687

8788
export type { TGQLError } from './graphql'

src/spec/utils.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,5 @@ export type TToastOption = {
215215
position?: TToastPos
216216
duration?: number
217217
}
218+
219+
export type TPublishMode = 'default' | 'changelog' | 'help'

src/widgets/Buttons/MenuButton/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ type TProps = {
1818
extraOptions?: TMenuOption[]
1919
placement?: TTooltipPlacement
2020
panelMinWidth?: string
21+
offset?: [number, number]
2122
onClick?: (key?: string) => void
2223
}
2324

2425
const MenuButton: FC<TProps> = ({
2526
children,
2627
options,
2728
extraOptions = [],
29+
offset = [5, 5],
2830
onClick = log,
2931
placement = 'top-end',
3032
panelMinWidth = '110px',
@@ -34,6 +36,7 @@ const MenuButton: FC<TProps> = ({
3436
placement={placement}
3537
trigger="click"
3638
hideOnClick
39+
offset={offset}
3740
content={
3841
<Menu
3942
options={options}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { SVG, PUBLISH_MODE } from '@/constant'
2+
3+
export const MORE_MENU = {
4+
[PUBLISH_MODE.DEFAULT]: [
5+
{
6+
key: 'feedback',
7+
icon: SVG.FEATURE,
8+
title: '功能建议',
9+
},
10+
{
11+
key: 'question',
12+
icon: SVG.QUESTION,
13+
title: '问题 / 求助',
14+
},
15+
{
16+
key: 'bug',
17+
icon: SVG.BUG,
18+
title: 'Bug / 吐槽',
19+
},
20+
{
21+
key: 'other',
22+
icon: SVG.MORE,
23+
title: '其它话题',
24+
},
25+
],
26+
[PUBLISH_MODE.CHANGELOG]: [],
27+
}
28+
29+
export const holder = 1

src/widgets/Buttons/PublishButton/index.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@
66

77
import { memo, FC } from 'react'
88
import Router from 'next/router'
9+
import { isEmpty } from 'ramda'
910

10-
import type { TThread } from '@/spec'
11+
import type { TThread, TPublishMode } from '@/spec'
12+
import { THREAD, HCN, SVG, PUBLISH_MODE } from '@/constant'
1113

12-
import { THREAD, HCN } from '@/constant'
1314
import { buildLog } from '@/utils/logger'
1415
import { authWarn } from '@/utils/helper'
1516
import { useAccount } from '@/hooks'
1617

18+
import { MORE_MENU } from './constant'
19+
import IconButton from '../IconButton'
20+
import MenuButton from '../MenuButton'
21+
1722
import PostLayout from './PostLayout'
1823
import WorksLayout from './WorksLayout'
1924

20-
import { Wrapper, PubButton } from '../styles/publish_button'
25+
import { Wrapper, PubButton, MoreOption } from '../styles/publish_button'
2126
import { getTargetPage, getText } from './helper'
2227

2328
/* eslint-disable-next-line */
@@ -27,15 +32,20 @@ type TProps = {
2732
thread?: TThread
2833
community?: string
2934
text?: string
35+
mode?: TPublishMode
3036
}
3137

3238
const PublishButton: FC<TProps> = ({
3339
thread = THREAD.POST,
3440
community = HCN,
3541
text = getText(thread),
42+
mode = PUBLISH_MODE.DEFAULT,
3643
}) => {
3744
const accountInfo = useAccount()
3845

46+
const menuOptions = MORE_MENU[mode]
47+
const hasNoMenu = isEmpty(menuOptions)
48+
3949
return (
4050
<Wrapper>
4151
<PubButton
@@ -51,6 +61,17 @@ const PublishButton: FC<TProps> = ({
5161
<PostLayout text={text} />
5262
)}
5363
</PubButton>
64+
{!hasNoMenu && (
65+
<MoreOption>
66+
<MenuButton
67+
placement="bottom-end"
68+
options={menuOptions}
69+
offset={[-5, 14]}
70+
>
71+
<IconButton icon={SVG.MOREL} />
72+
</MenuButton>
73+
</MoreOption>
74+
)}
5475
</Wrapper>
5576
)
5677
}

src/widgets/Buttons/styles/publish_button/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import styled from 'styled-components'
44
import css from '@/utils/css'
55

66
import Button from '../../Button'
7-
87
// see example: https://codepen.io/mydearxym2/pen/qBEvvpo
98

109
export const Wrapper = styled.div`
10+
${css.flex('align-center')};
1111
width: 100%;
1212
`
1313
export const PubButton = styled(Button)`
@@ -17,7 +17,11 @@ export const PubButton = styled(Button)`
1717
border: none;
1818
font-weight: 600;
1919
background: #3b434a; // to-theme
20-
color: #fff; // to-theme
20+
color: white; // to-theme
2121
height: 33px;
2222
border-radius: 15px;
2323
`
24+
export const MoreOption = styled.div`
25+
${css.flex('align-both')};
26+
margin-left: 3px;
27+
`

src/widgets/Icons/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,27 @@ import MoreDotIcon from './menu/MoreDot'
3131
import QRCodeIcon from './menu/QRCode'
3232
import ReportIcon from './menu/Report'
3333

34+
//
35+
import LightIcon from './Light'
36+
import BugIcon from './Bug'
37+
import QuestionIcon from './Question'
38+
3439
type TstyledFn = (comp: FC) => FC
3540

3641
export const getLocalSVG = (type: string, styledFn: TstyledFn): FC => {
3742
switch (type) {
43+
case SVG.FEATURE: {
44+
return styledFn(LightIcon)
45+
}
46+
47+
case SVG.BUG: {
48+
return styledFn(BugIcon)
49+
}
50+
51+
case SVG.QUESTION: {
52+
return styledFn(QuestionIcon)
53+
}
54+
3855
case SVG.REPORT: {
3956
return styledFn(ReportIcon)
4057
}

utils/constant/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ export {
4545
/* some svg icon are sensitive to fill color */
4646
/* some community svg need fill color, like city etc.. */
4747
export const NON_FILL_COMMUNITY = ['javascript']
48+
49+
export { PUBLISH_MODE } from './publish'

0 commit comments

Comments
 (0)