forked from evgeny-nadymov/telegram-react
-
Notifications
You must be signed in to change notification settings - Fork 0
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
evgeny-nadymov
committed
Feb 20, 2020
1 parent
d7f518c
commit c3525b8
Showing
19 changed files
with
375 additions
and
50 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
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
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 |
---|---|---|
|
@@ -20,4 +20,5 @@ | |
|
||
.chat-info-dialog-paper { | ||
width: 336px; | ||
align-self: flex-start; | ||
} |
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,6 @@ | ||
/* | ||
* Copyright (c) 2018-present, Evgeny Nadymov | ||
* | ||
* This source code is licensed under the GPL v.3.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ |
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,49 @@ | ||
/* | ||
* Copyright (c) 2018-present, Evgeny Nadymov | ||
* | ||
* This source code is licensed under the GPL v.3.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import User from '../Tile/User'; | ||
import UserPlaceholder from '../Tile/UserPlaceholder'; | ||
import { openUser } from '../../Actions/Client'; | ||
import TdLibController from '../../Controllers/TdLibController'; | ||
import './PollOptionResult.css'; | ||
|
||
class PollOptionResult extends React.Component { | ||
onClick = () => { | ||
const { userId } = this.props; | ||
if (!userId) return; | ||
|
||
openUser(userId, true); | ||
|
||
setTimeout(() => { | ||
TdLibController.clientUpdate({ | ||
'@type': 'clientUpdateClosePollResults' | ||
}); | ||
}, 0); | ||
}; | ||
|
||
render() { | ||
const { index, userId } = this.props; | ||
|
||
const content = userId ? <User userId={userId} showStatus={false} /> : <UserPlaceholder index={index} />; | ||
|
||
return ( | ||
<ListItem button className='list-item' onClick={this.onClick}> | ||
{content} | ||
</ListItem> | ||
); | ||
} | ||
} | ||
|
||
PollOptionResult.propTypes = { | ||
index: PropTypes.number.isRequired, | ||
userId: PropTypes.number | ||
}; | ||
|
||
export default PollOptionResult; |
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,27 @@ | ||
/* | ||
* Copyright (c) 2018-present, Evgeny Nadymov | ||
* | ||
* This source code is licensed under the GPL v.3.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
.poll-option-results-caption { | ||
position: sticky; | ||
top: 0; | ||
padding: 17px 24px 18px; | ||
color: var(--text-secondary); | ||
background: var(--background-paper); | ||
display: flex; | ||
flex-direction: row; | ||
z-index: 2; | ||
} | ||
|
||
.poll-option-results-answer { | ||
flex-grow: 1; | ||
flex-shrink: 1; | ||
} | ||
|
||
.poll-option-results-count { | ||
margin-left: 9px; | ||
flex-grow: 0; | ||
flex-shrink: 0; | ||
} |
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,114 @@ | ||
/* | ||
* Copyright (c) 2018-present, Evgeny Nadymov | ||
* | ||
* This source code is licensed under the GPL v.3.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import PollOptionResult from './PollOptionResult'; | ||
import { loadUsersContent } from '../../Utils/File'; | ||
import { POLL_RESULTS_FIRST_SLICE_LENGTH, POLL_RESULTS_LEAVE_LENGTH } from '../../Constants'; | ||
import FileStore from '../../Stores/FileStore'; | ||
import TdLibController from '../../Controllers/TdLibController'; | ||
import './PollOptionResults.css'; | ||
|
||
class PollOptionResults extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
const { option } = this.props; | ||
|
||
const count = | ||
option && option.voter_count <= POLL_RESULTS_FIRST_SLICE_LENGTH | ||
? option.voter_count | ||
: POLL_RESULTS_FIRST_SLICE_LENGTH - POLL_RESULTS_LEAVE_LENGTH; | ||
|
||
this.state = { | ||
voters: [], | ||
offset: 0, | ||
count | ||
}; | ||
} | ||
|
||
async updateVoters() { | ||
const { chatId, messageId, optionId, option } = this.props; | ||
const { offset, voters, count } = this.state; | ||
if (count <= 0) return; | ||
|
||
const result = await TdLibController.send({ | ||
'@type': 'getPollVoters', | ||
chat_id: chatId, | ||
message_id: messageId, | ||
option_id: optionId, | ||
offset: offset, | ||
limit: count | ||
}); | ||
|
||
if (this.props.option !== option) { | ||
return; | ||
} | ||
|
||
const store = FileStore.getStore(); | ||
loadUsersContent(store, result.user_ids); | ||
|
||
this.setState({ | ||
voters: [...voters, ...result.user_ids] | ||
}); | ||
} | ||
|
||
componentDidMount() { | ||
this.updateVoters(); | ||
} | ||
|
||
async componentDidUpdate(prevProps, prevState, snapshot) { | ||
if (prevProps.count !== this.props.count) { | ||
this.updateVoters(); | ||
} | ||
} | ||
|
||
render() { | ||
const { option, isQuiz } = this.props; | ||
const { voters, count } = this.state; | ||
|
||
const { text, voter_count, vote_percentage } = option; | ||
if (voter_count === 0) { | ||
return null; | ||
} | ||
|
||
const results = []; | ||
for (let i = 0; i < count; i++) { | ||
const userId = i < voters.length ? voters[i] : null; | ||
results.push(<PollOptionResult key={`${i}_userId=${userId}`} index={i} userId={userId} />); | ||
} | ||
|
||
const voterCount = isQuiz | ||
? count === 1 | ||
? `${count} answers` | ||
: `${count} answer` | ||
: count === 1 | ||
? `${count} votes` | ||
: `${count} vote`; | ||
|
||
return ( | ||
<> | ||
<div className='poll-option-results-caption'> | ||
<div className='poll-option-results-answer'>{`${text} — ${vote_percentage}%`}</div> | ||
<div className='poll-option-results-count'>{voterCount}</div> | ||
</div> | ||
{results} | ||
</> | ||
); | ||
} | ||
} | ||
|
||
PollOptionResults.propTypes = { | ||
chatId: PropTypes.number.isRequired, | ||
messageId: PropTypes.number.isRequired, | ||
optionId: PropTypes.number.isRequired, | ||
option: PropTypes.object.isRequired, | ||
isQuiz: PropTypes.bool.isRequired | ||
}; | ||
|
||
export default PollOptionResults; |
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,10 @@ | ||
/* | ||
* Copyright (c) 2018-present, Evgeny Nadymov | ||
* | ||
* This source code is licensed under the GPL v.3.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
.poll-results-content { | ||
padding: 0; | ||
} |
Oops, something went wrong.