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

74 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-01-22 12:57:05 +05:00
import React, { useEffect, useState } from 'react';
import { FlatList, View } from 'react-native';
2022-02-28 23:25:18 +05:00
import { useThemeStore } from '../../stores/theme';
import { useMessageStore } from '../../stores/stores';
import { DDS } from '../../services/device-detection';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
2022-02-28 13:48:59 +05:00
import { eCloseAnnouncementDialog, eOpenAnnouncementDialog } from '../../utils/events';
import BaseDialog from '../dialog/base-dialog';
2022-01-22 12:57:05 +05:00
import { allowedOnPlatform, renderItem } from './functions';
2021-11-22 15:12:26 +05:00
2021-11-23 15:06:35 +05:00
export const AnnouncementDialog = () => {
2022-02-28 23:25:18 +05:00
const colors = useThemeStore(state => 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-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}
2022-01-22 12:57:05 +05:00
visible={visible}
>
2021-11-22 15:12:26 +05:00
<View
style={{
2021-12-02 21:21:00 +05:00
width: DDS.isTab ? 600 : '100%',
2021-11-22 15:12:26 +05:00
backgroundColor: colors.bg,
2021-12-02 21:21:00 +05:00
maxHeight: DDS.isTab ? '90%' : '100%',
borderRadius: DDS.isTab ? 10 : 0,
overflow: 'hidden',
marginBottom: DDS.isTab ? 20 : 0
2022-01-22 12:57:05 +05:00
}}
>
2021-11-22 15:12:26 +05:00
<FlatList
style={{
width: '100%'
}}
2021-12-02 21:21:00 +05:00
data={info?.body.filter(item => allowedOnPlatform(item.platforms))}
2021-11-22 15:12:26 +05:00
renderItem={renderItem}
/>
<View
style={{
height: 15
}}
/>
</View>
</BaseDialog>
);
};