Vitalik
3 years ago
41 changed files with 320 additions and 521 deletions
@ -1,85 +1,86 @@
@@ -1,85 +1,86 @@
|
||||
import { |
||||
$size, |
||||
BottomModal, |
||||
Button, |
||||
useEventsListener, |
||||
useTheme, |
||||
$size, |
||||
BottomModal, |
||||
Button, |
||||
useEventsListener, |
||||
useTheme, |
||||
} from '@/shared' |
||||
import { PartialTheme } from '@/shared/themes/interfaces' |
||||
import React, { FC, useRef, useState } from 'react' |
||||
import { StyleSheet } from 'react-native' |
||||
import React, { FC, useEffect, useRef, useState } from 'react' |
||||
import { Image, StyleSheet } from 'react-native' |
||||
import RBSheet from 'react-native-raw-bottom-sheet' |
||||
import FastImage from 'react-native-fast-image' |
||||
import { fsService } from '@/services/system' |
||||
|
||||
interface ChatSendImgModalSettings { |
||||
onSend: () => void |
||||
onSend: () => void |
||||
} |
||||
|
||||
export const ChatSendImgModal: FC = () => { |
||||
const { styles } = useTheme(createStyles) |
||||
const { styles } = useTheme(createStyles) |
||||
|
||||
const [imgUrl, setImgUrl] = useState('') |
||||
const [imgUrl, setImgUrl] = useState('') |
||||
|
||||
const sheetRef = useRef<RBSheet>() |
||||
const settingsRef = useRef<ChatSendImgModalSettings>({ |
||||
onSend: null, |
||||
}) |
||||
const sheetRef = useRef<RBSheet>() |
||||
const settingsRef = useRef<ChatSendImgModalSettings>({ |
||||
onSend: null, |
||||
}) |
||||
|
||||
useEventsListener( |
||||
'chatSendImgModal', |
||||
data => { |
||||
sheetRef.current.open() |
||||
try { |
||||
settingsRef.current.onSend = data.onSend |
||||
setImgUrl(data.url) |
||||
} catch (err) { |
||||
console.log('APP-EVENT chatSendImgModal ERR: ', err) |
||||
} |
||||
}, |
||||
[sheetRef.current, settingsRef.current], |
||||
) |
||||
useEventsListener( |
||||
'chatSendImgModal', |
||||
data => { |
||||
sheetRef.current.open() |
||||
try { |
||||
settingsRef.current.onSend = data.onSend |
||||
setImgUrl(data.url) |
||||
} catch (err) { |
||||
console.log('APP-EVENT chatSendImgModal ERR: ', err) |
||||
} |
||||
}, |
||||
[sheetRef.current, settingsRef.current], |
||||
) |
||||
|
||||
const onSend = () => { |
||||
settingsRef.current.onSend() |
||||
sheetRef.current.close() |
||||
} |
||||
const onSend = () => { |
||||
settingsRef.current.onSend() |
||||
sheetRef.current.close() |
||||
} |
||||
|
||||
const onCancel = () => { |
||||
sheetRef.current.close() |
||||
} |
||||
const onCancel = () => { |
||||
sheetRef.current.close() |
||||
} |
||||
|
||||
return ( |
||||
<BottomModal |
||||
sheetRef={ref => (sheetRef.current = ref)} |
||||
height={$size(400, 300)} |
||||
containerStyle={styles.container}> |
||||
<FastImage |
||||
source={{ uri: imgUrl }} |
||||
style={styles.img} |
||||
resizeMode="contain" |
||||
/> |
||||
return ( |
||||
<BottomModal |
||||
sheetRef={ref => (sheetRef.current = ref)} |
||||
height={$size(400, 300)} |
||||
containerStyle={styles.container}> |
||||
<FastImage |
||||
source={{ uri: imgUrl }} |
||||
style={styles.img} |
||||
resizeMode="contain" |
||||
/> |
||||
|
||||
<Button |
||||
title={'Надiслати фото'} |
||||
type={'border'} |
||||
style={styles.sendBtn} |
||||
onPress={onSend} |
||||
/> |
||||
<Button |
||||
title={'Надiслати фото'} |
||||
type={'border'} |
||||
style={styles.sendBtn} |
||||
onPress={onSend} |
||||
/> |
||||
|
||||
<Button title={'Скасувати'} onPress={onCancel} /> |
||||
</BottomModal> |
||||
) |
||||
<Button title={'Скасувати'} onPress={onCancel} /> |
||||
</BottomModal> |
||||
) |
||||
} |
||||
|
||||
const createStyles = (theme: PartialTheme) => |
||||
StyleSheet.create({ |
||||
container: {}, |
||||
img: { |
||||
height: '60%', |
||||
width: '100%', |
||||
marginBottom: $size(15), |
||||
}, |
||||
sendBtn: { |
||||
marginBottom: $size(15), |
||||
}, |
||||
}) |
||||
StyleSheet.create({ |
||||
container: {}, |
||||
img: { |
||||
height: '60%', |
||||
width: '100%', |
||||
marginBottom: $size(15), |
||||
}, |
||||
sendBtn: { |
||||
marginBottom: $size(15), |
||||
}, |
||||
}) |
||||
|
@ -1,42 +0,0 @@
@@ -1,42 +0,0 @@
|
||||
import { ITaskPreview, useFlatList } from '@/shared' |
||||
import { tasksService } from '@/services/domain' |
||||
import { useEffect } from 'react' |
||||
import { ITaskPreviewResponse } from '@/api/tasks/responses.interface' |
||||
import { transformTasksInList } from '@/api/tasks/transform' |
||||
import { useTaskListEvents } from './use-task-list-events.hook' |
||||
|
||||
export const useFetchGroupTasks = (groupId: number) => { |
||||
const { |
||||
items, |
||||
isLoading, |
||||
isLoadingNext, |
||||
loadMore, |
||||
resetFlatList, |
||||
_setItems, |
||||
} = useFlatList({ |
||||
fetchItems: params => tasksService.getGroupTasks(groupId, params), |
||||
serrializatorItems: (items: ITaskPreviewResponse[]) => |
||||
transformTasksInList(items), |
||||
needInit: true, |
||||
loadParams: { |
||||
sort: 'DESC', |
||||
sortField: 'id', |
||||
}, |
||||
limit: 10, |
||||
}) |
||||
|
||||
useEffect(() => resetFlatList(), [groupId]) |
||||
|
||||
useTaskListEvents({ |
||||
items, |
||||
onReload: () => resetFlatList(), |
||||
setItems: (items: ITaskPreview[]) => _setItems(items), |
||||
}) |
||||
|
||||
return { |
||||
items, |
||||
isLoading, |
||||
isLoadingNext, |
||||
loadMore, |
||||
} |
||||
} |
@ -1,53 +0,0 @@
@@ -1,53 +0,0 @@
|
||||
import { createFullName, ITaskPreview, useFlatList } from '@/shared' |
||||
import { tasksService } from '@/services/domain' |
||||
import { useEffect } from 'react' |
||||
import { useSelector } from 'react-redux' |
||||
import { selectAccount } from '@/store/account' |
||||
import _ from 'lodash' |
||||
import { transformTasksInList } from '@/api/tasks/transform' |
||||
import { ITaskPreviewResponse } from '@/api/tasks/responses.interface' |
||||
import { useTaskListEvents } from './use-task-list-events.hook' |
||||
|
||||
export const useFetchMyTasks = ( |
||||
loadParams: { [key: string]: string | boolean }, |
||||
limit: number, |
||||
) => { |
||||
const account = useSelector(selectAccount) |
||||
const shortAccount = { |
||||
id: account.id, |
||||
fullName: createFullName(account.info.firstName, account.info.lastName), |
||||
avatarUrl: account.info.avatarUrl, |
||||
} |
||||
|
||||
const { |
||||
items: myTasks, |
||||
isLoading, |
||||
isLoadingNext, |
||||
loadMore, |
||||
resetFlatList, |
||||
_setItems, |
||||
} = useFlatList({ |
||||
fetchItems: params => tasksService.getMyTasks(params), |
||||
serrializatorItems: (items: ITaskPreviewResponse[]) => |
||||
transformTasksInList(items, shortAccount), |
||||
needInit: true, |
||||
loadParams, |
||||
limit, |
||||
}) |
||||
|
||||
useEffect(() => resetFlatList(), []) |
||||
|
||||
useTaskListEvents({ |
||||
items: myTasks, |
||||
onReload: () => resetFlatList(), |
||||
setItems: (items: ITaskPreview[]) => _setItems(items), |
||||
}) |
||||
|
||||
return { |
||||
myTasks, |
||||
isLoading, |
||||
isLoadingNext, |
||||
loadMore, |
||||
reloadTasks: resetFlatList |
||||
} |
||||
} |
@ -1,50 +0,0 @@
@@ -1,50 +0,0 @@
|
||||
import { ITaskPreview, useFlatList } from '@/shared' |
||||
import { tasksService } from '@/services/domain' |
||||
import { useEffect } from 'react' |
||||
import { ITaskPreviewResponse } from '@/api/tasks/responses.interface' |
||||
import { transformTasksInList } from '@/api/tasks/transform' |
||||
import { useTaskListEvents } from './use-task-list-events.hook' |
||||
|
||||
export const useFetchUserTasks = (user: { |
||||
id: number |
||||
fullName: string |
||||
avatarUrl: string |
||||
}) => { |
||||
const { |
||||
items, |
||||
isLoading, |
||||
isLoadingNext, |
||||
loadMore, |
||||
resetFlatList, |
||||
_setItems, |
||||
} = useFlatList({ |
||||
fetchItems: params => tasksService.getUserTasks(user.id, params), |
||||
serrializatorItems: (items: ITaskPreviewResponse[]) => |
||||
transformTasksInList(items, { |
||||
id: user.id, |
||||
fullName: user.fullName, |
||||
avatarUrl: user.avatarUrl, |
||||
}), |
||||
needInit: true, |
||||
loadParams: { |
||||
sort: 'DESC', |
||||
sortField: 'id', |
||||
}, |
||||
limit: 10, |
||||
}) |
||||
|
||||
useTaskListEvents({ |
||||
items, |
||||
onReload: () => resetFlatList(), |
||||
setItems: (items: ITaskPreview[]) => _setItems(items), |
||||
}) |
||||
|
||||
useEffect(() => resetFlatList(), [user.id]) |
||||
|
||||
return { |
||||
items, |
||||
isLoading, |
||||
isLoadingNext, |
||||
loadMore, |
||||
} |
||||
} |
Loading…
Reference in new issue