disallow duplicate group name

This commit is contained in:
刘浩远 2020-07-31 11:38:40 +08:00
parent d26c1c38d0
commit 440fafc1a9
6 changed files with 37 additions and 10 deletions

View File

@ -217,6 +217,19 @@ class GroupsTab extends React.Component<GroupsTabProps, GroupsTabState> {
this.setState({[name]: event.target.value})
}
validateNewGroupName = (v: string) => {
const name = v.trim()
if (name.length == 0) {
return intl.get("emptyName")
}
for (let group of this.props.groups) {
if (group.isMultiple && group.name === name) {
return intl.get("groups.exist")
}
}
return ""
}
createGroup = (event: React.FormEvent) => {
event.preventDefault()
let trimmed = this.state.newGroupName.trim()
@ -283,7 +296,7 @@ class GroupsTab extends React.Component<GroupsTabProps, GroupsTabState> {
<Stack horizontal>
<Stack.Item grow>
<TextField
onGetErrorMessage={v => v.trim().length == 0 ? intl.get("emptyName") : ""}
onGetErrorMessage={this.validateNewGroupName}
validateOnLoad={false}
placeholder={intl.get("groups.enterName")}
value={this.state.newGroupName}
@ -293,7 +306,7 @@ class GroupsTab extends React.Component<GroupsTabProps, GroupsTabState> {
</Stack.Item>
<Stack.Item>
<PrimaryButton
disabled={this.state.newGroupName.trim().length == 0}
disabled={this.validateNewGroupName(this.state.newGroupName) !== ""}
type="sumbit"
text={intl.get("create")} />
</Stack.Item>

View File

@ -6,7 +6,7 @@ export class SourceGroup {
index?: number // available only from groups tab container
constructor(sids: number[], name: string = null) {
name = (name && name.trim()) || "订阅源组"
name = (name && name.trim()) || "Source group"
if (sids.length == 1) {
this.isMultiple = false
} else {

View File

@ -101,7 +101,7 @@
"fetching": "Updating sources, please wait …",
"exit": "Exit settings",
"sources": "Sources",
"grouping": "Grouping",
"grouping": "Groups",
"rules": "Rules",
"app": "Preferences",
"about": "About",
@ -137,6 +137,7 @@
"selectedMulti": "Selected multiple sources"
},
"groups": {
"exist": "This group already exists.",
"type": "Type",
"group": "Group",
"source": "Source",

View File

@ -135,6 +135,7 @@
"selectedMulti": "选中多个订阅源"
},
"groups": {
"exist": "该分组已存在",
"type": "类型",
"group": "分组",
"source": "订阅源",

View File

@ -64,9 +64,16 @@ export function createSourceGroupDone(group: SourceGroup): SourceGroupActionType
export function createSourceGroup(name: string): AppThunk<number> {
return (dispatch, getState) => {
let groups = getState().groups
for (let i = 0; i < groups.length; i += 1) {
const g = groups[i]
if (g.isMultiple && g.name === name) {
return i
}
}
let group = new SourceGroup([], name)
dispatch(createSourceGroupDone(group))
let groups = getState().groups
groups = getState().groups
window.settings.saveGroups(groups)
return groups.length - 1
}

View File

@ -86,11 +86,16 @@ export function switchView(viewType: ViewType): PageActionTypes {
}
}
export function showItem(feedId: string, item: RSSItem): PageActionTypes {
return {
type: SHOW_ITEM,
feedId: feedId,
item: item
export function showItem(feedId: string, item: RSSItem): AppThunk {
return (dispatch, getState) => {
const state = getState()
if (state.items.hasOwnProperty(item._id) && state.sources.hasOwnProperty(item.source)) {
dispatch({
type: SHOW_ITEM,
feedId: feedId,
item: item
})
}
}
}
export function showItemFromId(iid: string): AppThunk {