-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
98 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ node_modules/ | |
/js/panels.js | ||
/js/panel-mainmenu.js | ||
/js/panel-rooms.js | ||
/js/panel-chat.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,6 @@ package-lock.json | |
/js/panels.js | ||
/js/panel-mainmenu.js | ||
/js/panel-rooms.js | ||
/js/panel-chat.js | ||
|
||
.vscode |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Chat panel | ||
* | ||
* @author Guangcong Luo <guangcongluo@gmail.com> | ||
* @license AGPLv3 | ||
*/ | ||
|
||
class ChatRoom extends PSRoom { | ||
readonly classType: string = 'chat'; | ||
constructor(options: RoomOptions) { | ||
super(options); | ||
if (!this.connected && PS.connected) { | ||
PS.send(`|/join ${this.id}`); | ||
this.connected = true; | ||
} | ||
} | ||
receive(line: string) { | ||
this.update(line); | ||
} | ||
} | ||
|
||
class ChatPanel extends preact.Component<{style: {}, room: PSRoom}> { | ||
render() { | ||
return <div class="ps-room ps-room-light scrollabel" id={`room-${this.props.room.id}`} style={this.props.style}> | ||
<div class="tournament-wrapper hasuserlist"></div> | ||
<div class="chat-log hasuserlist"> | ||
<ChatLog room={this.props.room} /> | ||
</div> | ||
<div class="chat-log-add hasuserlist"></div> | ||
<ul class="userlist"></ul> | ||
</div>; | ||
} | ||
} | ||
|
||
class ChatLog extends preact.Component<{room: PSRoom}> { | ||
componentDidMount() { | ||
this.props.room.subscribe(msg => { | ||
if (!msg) return; | ||
this.append(<div class="chat">{msg}</div>); | ||
}); | ||
} | ||
append(nodes: preact.ComponentChild) { | ||
preact.render(nodes, this.base!); | ||
} | ||
shouldComponentUpdate() { | ||
return false; | ||
} | ||
render() { | ||
return <div class="inner" role="log"></div>; | ||
} | ||
} | ||
|
||
PS.roomTypes['chat'] = { | ||
Model: ChatRoom, | ||
Component: ChatPanel, | ||
}; | ||
PS.updateRoomTypes(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters