Statistics: Various fixes (#1835)

This commit is contained in:
Alexander Zinchuk 2022-04-20 14:32:05 +02:00
parent 7d63a7f812
commit 41354161b9
7 changed files with 22 additions and 14 deletions

View File

@ -40,7 +40,7 @@ export type OwnProps = {
}; };
export type StateProps = { export type StateProps = {
statistics: ApiMessageStatistics; statistics?: ApiMessageStatistics;
messageId?: number; messageId?: number;
dcId?: number; dcId?: number;
}; };
@ -99,7 +99,7 @@ const Statistics: FC<OwnProps & StateProps> = ({
return; return;
} }
if (!statistics) { if (!statistics || !containerRef.current) {
return; return;
} }
@ -161,10 +161,11 @@ const Statistics: FC<OwnProps & StateProps> = ({
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => { (global, { chatId }): StateProps => {
const { currentMessage, currentMessageId } = global.statistics;
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const dcId = chat?.fullInfo?.statisticsDcId; const dcId = chat?.fullInfo?.statisticsDcId;
const statistics = global.statistics.currentMessage;
const messageId = global.statistics.currentMessageId;
return { statistics: currentMessage, dcId, messageId: currentMessageId }; return { statistics, dcId, messageId };
}, },
)(Statistics)); )(Statistics));

View File

@ -4,11 +4,11 @@
overflow-y: hidden; overflow-y: hidden;
&__messages { &__messages {
padding: 1rem 0.75rem; padding: 1rem 0.25rem;
border-top: 1px solid var(--color-borders); border-top: 1px solid var(--color-borders);
&-title { &-title {
padding-left: 0.25rem; padding-left: 0.75rem;
font-size: 16px; font-size: 16px;
color: var(--text-color); color: var(--text-color);
line-height: 30px; line-height: 30px;

View File

@ -15,6 +15,7 @@ import { selectChat, selectStatistics } from '../../../global/selectors';
import buildClassName from '../../../util/buildClassName'; import buildClassName from '../../../util/buildClassName';
import useLang from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang';
import useForceUpdate from '../../../hooks/useForceUpdate';
import Loading from '../../ui/Loading'; import Loading from '../../ui/Loading';
import StatisticsOverview from './StatisticsOverview'; import StatisticsOverview from './StatisticsOverview';
@ -84,6 +85,7 @@ const Statistics: FC<OwnProps & StateProps> = ({
const loadedCharts = useRef<string[]>([]); const loadedCharts = useRef<string[]>([]);
const { loadStatistics, loadStatisticsAsyncGraph } = getActions(); const { loadStatistics, loadStatisticsAsyncGraph } = getActions();
const forceUpdate = useForceUpdate();
useEffect(() => { useEffect(() => {
loadStatistics({ chatId, isGroup }); loadStatistics({ chatId, isGroup });
@ -169,9 +171,11 @@ const Statistics: FC<OwnProps & StateProps> = ({
loadedCharts.current.push(name); loadedCharts.current.push(name);
}); });
forceUpdate();
})(); })();
}, [ }, [
graphs, graphTitles, isReady, statistics, lang, chatId, loadStatisticsAsyncGraph, dcId, graphs, graphTitles, isReady, statistics, lang, chatId, loadStatisticsAsyncGraph, dcId, forceUpdate,
]); ]);
if (!isReady || !statistics || messageId) { if (!isReady || !statistics || messageId) {

View File

@ -1,10 +1,15 @@
.StatisticsRecentMessage { .StatisticsRecentMessage {
position: relative; position: relative;
cursor: pointer; cursor: pointer;
margin-bottom: 1rem; padding: 0.5rem;
border-radius: var(--border-radius-default-small);
&:hover, &:active {
background-color: var(--color-chat-hover);
}
&--with-image { &--with-image {
padding-left: 3rem; padding-left: 3.5rem;
} }
&__summary { &__summary {
@ -18,8 +23,8 @@
width: 2.5rem; width: 2.5rem;
height: 2.5rem; height: 2.5rem;
position: absolute; position: absolute;
left: 0; left: 0.5rem;
top: 0; top: 0.5rem;
object-fit: cover; object-fit: cover;
border-radius: 0.25rem; border-radius: 0.25rem;
margin-inline-end: 0.25rem; margin-inline-end: 0.25rem;

View File

@ -201,7 +201,6 @@ export const INITIAL_STATE: GlobalState = {
statistics: { statistics: {
byChatId: {}, byChatId: {},
currentMessage: {},
}, },
pollModal: { pollModal: {

View File

@ -9,7 +9,6 @@ export function updateStatistics(
return { return {
...global, ...global,
statistics: { statistics: {
currentMessage: {},
byChatId: { byChatId: {
...global.statistics.byChatId, ...global.statistics.byChatId,
[chatId]: statistics, [chatId]: statistics,

View File

@ -519,7 +519,7 @@ export type GlobalState = {
statistics: { statistics: {
byChatId: Record<string, ApiChannelStatistics | ApiGroupStatistics>; byChatId: Record<string, ApiChannelStatistics | ApiGroupStatistics>;
currentMessage: ApiMessageStatistics; currentMessage?: ApiMessageStatistics;
currentMessageId?: number; currentMessageId?: number;
}; };