Compare commits

...

3 Commits

  1. 2
      src/modules/chats/hooks/use-chat-details.hook.ts
  2. 22
      src/modules/chats/hooks/use-chats-list.hook.ts
  3. 4
      src/modules/chats/hooks/use-pined-messages.hook.ts
  4. 2
      src/modules/chats/smart-components/swipable-chat-row-card.smart-component.tsx
  5. 17
      src/modules/root/components/net-status.component.tsx
  6. 3
      src/shared/enums/error-message.enum.ts
  7. 3
      src/shared/enums/index.ts
  8. 2
      src/shared/helpers/get-error-code.helpers.ts

2
src/modules/chats/hooks/use-chat-details.hook.ts

@ -145,7 +145,7 @@ export const useChatDetails = (chatId: number | string) => { @@ -145,7 +145,7 @@ export const useChatDetails = (chatId: number | string) => {
useSocketListener('chat/delete-message', onMessageDeleted, [chatDetails])
// Для оновлення даних чату при закріплення повідомлення чату в режимі офлайн
// Для оновлення даних чату при закріпленні повідомлення чату в режимі офлайн
useEventsListener('onPinnedMessage', onPinedMessage, [chatDetails])
useEventsListener(

22
src/modules/chats/hooks/use-chats-list.hook.ts

@ -5,6 +5,7 @@ import { @@ -5,6 +5,7 @@ import {
ChatMemberRole,
ChatType,
createFullName,
ErrorMessage,
IChat,
RouteKey,
SocketEvents,
@ -27,6 +28,7 @@ import { showUknowError } from '@/shared/helpers/alert.helper' @@ -27,6 +28,7 @@ import { showUknowError } from '@/shared/helpers/alert.helper'
import { getChatIdFromMessages, isChatInList } from '../helpers'
import { SkeletonDataKey } from '@/services/system'
import { chatManager } from '@/managers'
import { getErrorMessage } from '@/shared/helpers'
export const useChatList = () => {
const nav = useNav()
@ -223,6 +225,14 @@ export const useChatList = () => { @@ -223,6 +225,14 @@ export const useChatList = () => {
} else handleClearForMe(chatId, chat.unreadMessagesCount)
}
const showMaxFixedError = () => {
appEvents.emit('openInfoModal', {
title: 'Максимум закріпленних чатів ',
message: 'можна закріпити лише 5 чатів',
pressButtonText: 'Продовжити',
})
}
const onPin = async (chatId: number | string) => {
try {
const chatIndex = chats.findIndex(it => it.id === chatId)
@ -230,11 +240,7 @@ export const useChatList = () => { @@ -230,11 +240,7 @@ export const useChatList = () => {
const pinned = chats.filter(it => it.isChatFixed)
if (pinned.length > 4) {
appEvents.emit('openInfoModal', {
title: 'Максимум закріпленних чатів ',
message: 'можна закріпити лише 5 чатів',
pressButtonText: 'Продовжити',
})
showMaxFixedError()
return
}
@ -255,7 +261,9 @@ export const useChatList = () => { @@ -255,7 +261,9 @@ export const useChatList = () => {
// _setItems(newList)
} catch (e) {
showUknowError()
const message = getErrorMessage(e)
if (message === ErrorMessage.MaxFixed) showMaxFixedError()
else showUknowError()
}
}
@ -334,7 +342,7 @@ export const useChatList = () => { @@ -334,7 +342,7 @@ export const useChatList = () => {
chats,
chat => chat.id.toString() === data.chatId.toString(),
)
console.log(!chat || chat.isChatFixed)
if (!chat || chat.isChatFixed) return
resetFlatList()
}

4
src/modules/chats/hooks/use-pined-messages.hook.ts

@ -10,6 +10,7 @@ import _ from 'lodash' @@ -10,6 +10,7 @@ import _ from 'lodash'
import { useCallback, useEffect, useState } from 'react'
import Clipboard from '@react-native-community/clipboard'
import { chatMessageManager } from '@/managers/chat-message.manager'
import { useNetInfo } from '@react-native-community/netinfo'
interface IProps {
messages: IChatMessage[]
@ -18,6 +19,7 @@ interface IProps { @@ -18,6 +19,7 @@ interface IProps {
}
export const usePinedMessages = ({ messages, role, onPress }: IProps) => {
const { isConnected } = useNetInfo()
const [activeInd, setActiveInd] = useState(null)
const nav = useNav()
@ -69,7 +71,7 @@ export const usePinedMessages = ({ messages, role, onPress }: IProps) => { @@ -69,7 +71,7 @@ export const usePinedMessages = ({ messages, role, onPress }: IProps) => {
]
const copyEnablesTypes = [MessageType.Text, MessageType.Image]
const canCopy = copyEnablesTypes.includes(messages[activeInd].type)
const canCopy = isConnected ? copyEnablesTypes.includes(messages[activeInd].type) : messages[activeInd].type === MessageType.Text
if (!canCopy) options.shift()

2
src/modules/chats/smart-components/swipable-chat-row-card.smart-component.tsx

@ -83,7 +83,7 @@ export const SwipableChatRowCardSmart: FC<IProps> = ({ @@ -83,7 +83,7 @@ export const SwipableChatRowCardSmart: FC<IProps> = ({
isChatUnread: isUnread,
}),
),
[id, unreadMessagesCount, theme, isPinned, isUnread],
[id, unreadMessagesCount, theme, isPinned, isUnread, onPressActionBtn],
)
return (

17
src/modules/root/components/net-status.component.tsx

@ -30,7 +30,11 @@ export const NetStatus: FC<INetStatusProps> = ({ status }) => { @@ -30,7 +30,11 @@ export const NetStatus: FC<INetStatusProps> = ({ status }) => {
return (
<>
{status === 'try' ? (
<View style={[styles.container, { paddingTop }]}>
<View
style={[
styles.container,
{ paddingTop, paddingBottom: $size(10) },
]}>
<View style={styles.txtRow}>
<Txt style={styles.txt}>Перевірка підключення</Txt>
<ActivityIndicator
@ -44,6 +48,10 @@ export const NetStatus: FC<INetStatusProps> = ({ status }) => { @@ -44,6 +48,10 @@ export const NetStatus: FC<INetStatusProps> = ({ status }) => {
styles.container,
{
paddingBottom: 0,
marginBottom: Platform.select({
ios: $size(-25),
android: 0,
}),
backgroundColor: 'transparent',
},
]}>
@ -89,13 +97,9 @@ export const NetStatus: FC<INetStatusProps> = ({ status }) => { @@ -89,13 +97,9 @@ export const NetStatus: FC<INetStatusProps> = ({ status }) => {
const createStyles = (theme: PartialTheme) =>
StyleSheet.create({
container: {
position: 'absolute',
top: 0,
left: 0,
backgroundColor: theme.netStatus.backgroundColor,
zIndex: 9999,
width: '100%',
paddingBottom: 15,
},
txt: {
color: theme.netStatus.textColor,
@ -127,7 +131,8 @@ const createStyles = (theme: PartialTheme) => @@ -127,7 +131,8 @@ const createStyles = (theme: PartialTheme) =>
justifyContent: 'flex-end',
paddingRight: $size(70),
width: '100%',
backgroundColor: 'transparent',
// backgroundColor: 'transparent',
backgroundColor: theme.$layoutBg,
},
button: {
backgroundColor: theme.netStatus.backgroundColor,

3
src/shared/enums/error-message.enum.ts

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
export enum ErrorMessage {
MaxFixed = 'Max fixed chats'
}

3
src/shared/enums/index.ts

@ -13,4 +13,5 @@ export * from './chat.enums' @@ -13,4 +13,5 @@ export * from './chat.enums'
export * from './btns-type.enum'
export * from './actions-queue-type.enum'
export * from './entity-type.enum'
export * from './permissions.enum'
export * from './permissions.enum'
export * from './error-message.enum'

2
src/shared/helpers/get-error-code.helpers.ts

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
export const getErrorCode = (error: any) => {
return error.response?.data?.statusCode || error.response?.data?.status
}
export const getErrorMessage = (error: any) => error.response?.data?.message

Loading…
Cancel
Save