Don't reset editor state if props didn't change. Fixes #34

This commit is contained in:
Tulir Asokan 2018-12-09 14:58:59 +02:00
parent 0e4cea6f52
commit 5704b3e53b
3 changed files with 21 additions and 2 deletions

View File

@ -8,7 +8,13 @@ class BaseMainView extends Component {
} }
componentWillReceiveProps(nextProps) { 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 () => { delete = async () => {
@ -25,8 +31,12 @@ class BaseMainView extends Component {
} }
} }
get entryKeys() {
return []
}
get initialState() { get initialState() {
throw Error("Not implemented") return {}
} }
get hasInstances() { get hasInstances() {

View File

@ -46,6 +46,11 @@ class Client extends BaseMainView {
this.deleteFunc = api.deleteClient this.deleteFunc = api.deleteClient
} }
get entryKeys() {
return ["id", "displayname", "homeserver", "avatar_url", "access_token", "sync",
"autojoin", "enabled", "started"]
}
get initialState() { get initialState() {
return { return {
id: "", id: "",

View File

@ -40,6 +40,10 @@ class Instance extends BaseMainView {
this.updateClientOptions() this.updateClientOptions()
} }
get entryKeys() {
return ["id", "primary_user", "enabled", "started", "type", "config"]
}
get initialState() { get initialState() {
return { return {
id: "", id: "",