fix group menu indexing

This commit is contained in:
刘浩远 2020-08-08 17:48:14 +08:00
parent 79d5a5861e
commit 7deb250bcc
5 changed files with 9 additions and 9 deletions

View File

@ -113,7 +113,7 @@ const utilsBridge = {
addTouchBarEventsListener: (callback: (IObjectWithKey) => any) => { addTouchBarEventsListener: (callback: (IObjectWithKey) => any) => {
ipcRenderer.removeAllListeners("touchbar-event") ipcRenderer.removeAllListeners("touchbar-event")
ipcRenderer.on("touchbar-event", (_, key: string) => { ipcRenderer.on("touchbar-event", (_, key: string) => {
callback({ key: key} ) callback({ key: key } )
}) })
}, },
initTouchBar: (texts: TouchBarTexts) => { initTouchBar: (texts: TouchBarTexts) => {

View File

@ -50,16 +50,16 @@ export class Menu extends React.Component<MenuProps> {
}, },
{ {
name: intl.get("menu.subscriptions"), name: intl.get("menu.subscriptions"),
links: this.props.groups.filter(g => g.sids.length > 0).map((g, i) => { links: this.props.groups.filter(g => g.sids.length > 0).map(g => {
if (g.isMultiple) { if (g.isMultiple) {
let sources = g.sids.map(sid => this.props.sources[sid]) let sources = g.sids.map(sid => this.props.sources[sid])
return { return {
name: g.name, name: g.name,
ariaLabel: this.countOverflow(sources.map(s => s.unreadCount).reduce((a, b) => a + b, 0)), ariaLabel: this.countOverflow(sources.map(s => s.unreadCount).reduce((a, b) => a + b, 0)),
key: "g-" + i, key: "g-" + g.index,
url: null, url: null,
isExpanded: g.expanded, isExpanded: g.expanded,
onClick: () => this.props.selectSourceGroup(g, "g-" + i), onClick: () => this.props.selectSourceGroup(g, "g-" + g.index),
links: sources.map(this.getSource) links: sources.map(this.getSource)
} }
} else { } else {

View File

@ -23,8 +23,8 @@ class Settings extends React.Component<SettingsProps> {
super(props) super(props)
} }
componentDidUpdate= (prevProps: SettingsProps) => { componentDidUpdate = (prevProps: SettingsProps) => {
if (this.props.display !== prevProps.display) { if (window.utils.platform === "darwin" && this.props.display !== prevProps.display) {
if (this.props.display) window.utils.destroyTouchBar() if (this.props.display) window.utils.destroyTouchBar()
else initTouchBarWithTexts() else initTouchBarWithTexts()
} }

View File

@ -23,7 +23,7 @@ const mapStateToProps = createSelector(
display: app.menu, display: app.menu,
selected: app.menuKey, selected: app.menuKey,
sources: sources, sources: sources,
groups: groups, groups: groups.map((g, i) => ({ ...g, index: i })),
searchOn: searchOn, searchOn: searchOn,
itemOn: itemOn, itemOn: itemOn,
}) })
@ -47,7 +47,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(openGroupMenu(sids, event)) dispatch(openGroupMenu(sids, event))
}, },
updateGroupExpansion: (event: React.MouseEvent<HTMLElement>, key: string, selected: string) => { updateGroupExpansion: (event: React.MouseEvent<HTMLElement>, key: string, selected: string) => {
if ((event.target as HTMLElement).tagName !== "DIV" || key === selected) { if ((event.target as HTMLElement).tagName === "I" || key === selected) {
let [type, index] = key.split("-") let [type, index] = key.split("-")
if (type === "g") dispatch(toggleGroupExpansion(parseInt(index))) if (type === "g") dispatch(toggleGroupExpansion(parseInt(index)))
} }

View File

@ -3,7 +3,7 @@ export class SourceGroup {
sids: number[] sids: number[]
name?: string name?: string
expanded?: boolean expanded?: boolean
index?: number // available only from groups tab container index?: number // available only from menu or groups tab container
constructor(sids: number[], name: string = null) { constructor(sids: number[], name: string = null) {
name = (name && name.trim()) || "Source group" name = (name && name.trim()) || "Source group"