Files
notesnook/apps/mobile/src/components/Announcements/index.js

73 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-11-22 15:12:26 +05:00
import React, {useEffect, useState} from 'react';
import {FlatList, View} from 'react-native';
import {useTracked} from '../../provider';
2021-11-23 15:06:35 +05:00
import {useMessageStore} from '../../provider/stores';
2021-11-22 15:12:26 +05:00
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
import {
eCloseAnnouncementDialog,
eOpenAnnouncementDialog
} from '../../utils/Events';
import BaseDialog from '../Dialog/base-dialog';
2021-12-02 10:39:06 +05:00
import {renderItem} from './functions';
2021-11-22 15:12:26 +05:00
2021-11-23 15:06:35 +05:00
export const AnnouncementDialog = () => {
2021-11-22 15:12:26 +05:00
const [state] = useTracked();
const colors = state.colors;
2021-11-23 15:06:35 +05:00
const [visible, setVisible] = useState(false);
const [info, setInfo] = useState(null);
const remove = useMessageStore(state => state.remove);
2021-11-22 15:12:26 +05:00
useEffect(() => {
eSubscribeEvent(eOpenAnnouncementDialog, open);
eSubscribeEvent(eCloseAnnouncementDialog, close);
return () => {
eUnSubscribeEvent(eOpenAnnouncementDialog, open);
eUnSubscribeEvent(eCloseAnnouncementDialog, close);
};
}, [visible]);
2021-11-23 15:06:35 +05:00
const open = data => {
setInfo(data);
2021-12-02 10:39:06 +05:00
console.log(info);
2021-11-22 15:12:26 +05:00
setVisible(true);
};
const close = () => {
2021-11-23 19:24:53 +05:00
if (visible) {
remove(info.id);
2021-11-23 19:24:53 +05:00
setInfo(null);
setVisible(false);
}
2021-11-22 15:12:26 +05:00
};
return (
<BaseDialog
animated={false}
centered={false}
bottom={true}
2021-11-23 15:06:35 +05:00
onRequestClose={close}
2021-11-22 15:12:26 +05:00
visible={visible}>
<View
style={{
2021-12-02 10:39:06 +05:00
width: '100%',
2021-11-22 15:12:26 +05:00
backgroundColor: colors.bg,
2021-12-02 10:39:06 +05:00
maxHeight: '100%'
2021-11-22 15:12:26 +05:00
}}>
<FlatList
style={{
width: '100%'
}}
2021-12-02 10:39:06 +05:00
data={info?.body}
2021-11-22 15:12:26 +05:00
renderItem={renderItem}
/>
<View
style={{
height: 15
}}
/>
</View>
</BaseDialog>
);
};