Proper client state init

canary
WolverinDEV 2020-04-27 20:22:14 +02:00
parent c300949923
commit cf0868f35b
1 changed files with 40 additions and 27 deletions

View File

@ -254,6 +254,11 @@ interface ClientNameState {
@BatchUpdateAssignment(BatchUpdateType.CHANNEL_TREE)
@ReactEventHandler<ClientName>(e => e.props.client.events)
class ClientName extends ReactComponentBase<ClientNameProperties, ClientNameState> {
protected initialize() {
this.updateGroups();
this.updateAwayMessage();
}
protected defaultState(): ClientNameState {
return {
group_prefix: "",
@ -268,14 +273,7 @@ class ClientName extends ReactComponentBase<ClientNameProperties, ClientNameStat
</div>
}
@EventHandler<ClientEvents>("notify_properties_updated")
private handlePropertiesChanged(event: ClientEvents["notify_properties_updated"]) {
if(typeof event.updated_properties.client_away !== "undefined" || typeof event.updated_properties.client_away_message !== "undefined") {
this.setState({
away_message: event.client_properties.client_away_message && " [" + event.client_properties.client_away_message + "]"
});
}
if(typeof event.updated_properties.client_servergroups !== "undefined" || typeof event.updated_properties.client_channel_group_id !== "undefined") {
private updateGroups() {
let prefix_groups: string[] = [];
let suffix_groups: string[] = [];
for(const group_id of this.props.client.assignedServerGroupIds()) {
@ -299,7 +297,22 @@ class ClientName extends ReactComponentBase<ClientNameProperties, ClientNameStat
this.setState({
group_suffix: suffix_groups.map(e => "[" + e + "]").join(""),
group_prefix: prefix_groups.map(e => "[" + e + "]").join("")
})
});
}
private updateAwayMessage() {
this.setState({
away_message: this.props.client.properties.client_away_message && " [" + this.props.client.properties.client_away_message + "]"
});
}
@EventHandler<ClientEvents>("notify_properties_updated")
private handlePropertiesChanged(event: ClientEvents["notify_properties_updated"]) {
if(typeof event.updated_properties.client_away !== "undefined" || typeof event.updated_properties.client_away_message !== "undefined") {
this.updateAwayMessage();
}
if(typeof event.updated_properties.client_servergroups !== "undefined" || typeof event.updated_properties.client_channel_group_id !== "undefined") {
this.updateGroups();
}
}
}