Don't reset editor state if props didn't change. Fixes #34
This commit is contained in:
parent
0e4cea6f52
commit
5704b3e53b
3 changed files with 21 additions and 2 deletions
|
@ -8,7 +8,13 @@ class BaseMainView extends Component {
|
|||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.setState(Object.assign(this.initialState, nextProps.entry))
|
||||
const newState = Object.assign(this.initialState, nextProps.entry)
|
||||
for (const key of this.entryKeys) {
|
||||
if (this.props.entry[key] === nextProps.entry[key]) {
|
||||
newState[key] = this.state[key]
|
||||
}
|
||||
}
|
||||
this.setState(newState)
|
||||
}
|
||||
|
||||
delete = async () => {
|
||||
|
@ -25,8 +31,12 @@ class BaseMainView extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
get entryKeys() {
|
||||
return []
|
||||
}
|
||||
|
||||
get initialState() {
|
||||
throw Error("Not implemented")
|
||||
return {}
|
||||
}
|
||||
|
||||
get hasInstances() {
|
||||
|
|
|
@ -46,6 +46,11 @@ class Client extends BaseMainView {
|
|||
this.deleteFunc = api.deleteClient
|
||||
}
|
||||
|
||||
get entryKeys() {
|
||||
return ["id", "displayname", "homeserver", "avatar_url", "access_token", "sync",
|
||||
"autojoin", "enabled", "started"]
|
||||
}
|
||||
|
||||
get initialState() {
|
||||
return {
|
||||
id: "",
|
||||
|
|
|
@ -40,6 +40,10 @@ class Instance extends BaseMainView {
|
|||
this.updateClientOptions()
|
||||
}
|
||||
|
||||
get entryKeys() {
|
||||
return ["id", "primary_user", "enabled", "started", "type", "config"]
|
||||
}
|
||||
|
||||
get initialState() {
|
||||
return {
|
||||
id: "",
|
||||
|
|
Loading…
Reference in a new issue