2021-11-23 15:06:35 +05:00
|
|
|
import React from 'react';
|
2022-01-22 12:57:05 +05:00
|
|
|
import { FlatList, View } from 'react-native';
|
2022-02-28 23:25:18 +05:00
|
|
|
import { useThemeStore } from '../../stores/theme';
|
|
|
|
|
import { useMessageStore, useSelectionStore } from '../../stores/stores';
|
2022-02-28 13:48:59 +05:00
|
|
|
import { Button } from '../ui/button';
|
2022-01-22 12:57:05 +05:00
|
|
|
import { allowedOnPlatform, renderItem } from './functions';
|
2022-03-09 15:19:28 +05:00
|
|
|
import { SIZE } from '../../utils/size';
|
2021-11-23 15:06:35 +05:00
|
|
|
|
2022-01-22 12:57:05 +05:00
|
|
|
export const Announcement = ({ color }) => {
|
2022-02-28 23:25:18 +05:00
|
|
|
const colors = useThemeStore(state => state.colors);
|
2021-11-23 15:06:35 +05:00
|
|
|
const announcements = useMessageStore(state => state.announcements);
|
|
|
|
|
const remove = useMessageStore(state => state.remove);
|
|
|
|
|
let announcement = announcements.length > 0 ? announcements[0] : null;
|
|
|
|
|
const selectionMode = useSelectionStore(state => state.selectionMode);
|
|
|
|
|
|
|
|
|
|
return !announcement || selectionMode ? null : (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: colors.bg,
|
2021-11-23 19:24:53 +05:00
|
|
|
width: '100%'
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-11-23 15:06:35 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: 12,
|
|
|
|
|
width: '100%',
|
|
|
|
|
borderRadius: 10,
|
2021-11-23 19:24:53 +05:00
|
|
|
overflow: 'hidden'
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-11-23 19:24:53 +05:00
|
|
|
<Button
|
2022-03-09 15:19:28 +05:00
|
|
|
type="error"
|
2021-11-23 19:24:53 +05:00
|
|
|
icon="close"
|
|
|
|
|
height={null}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
remove(announcement.id);
|
|
|
|
|
}}
|
2022-03-09 15:19:28 +05:00
|
|
|
hitSlop={{
|
|
|
|
|
left: 10,
|
|
|
|
|
top: 0,
|
|
|
|
|
bottom: 10,
|
|
|
|
|
right: 0
|
|
|
|
|
}}
|
|
|
|
|
title="Hide"
|
|
|
|
|
iconSize={16}
|
|
|
|
|
fontSize={SIZE.xs + 1}
|
2021-11-23 19:24:53 +05:00
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
top: 10,
|
2022-03-09 15:19:28 +05:00
|
|
|
right: 12,
|
2022-03-10 17:03:41 +05:00
|
|
|
paddingVertical: 4,
|
|
|
|
|
paddingHorizontal: 6,
|
|
|
|
|
zIndex: 999
|
2021-11-23 19:24:53 +05:00
|
|
|
}}
|
|
|
|
|
/>
|
2022-03-09 15:19:28 +05:00
|
|
|
|
2021-11-23 15:06:35 +05:00
|
|
|
<View>
|
|
|
|
|
<FlatList
|
|
|
|
|
style={{
|
2021-11-23 18:35:44 +05:00
|
|
|
width: '100%',
|
2021-11-23 19:24:53 +05:00
|
|
|
marginTop: 15
|
2021-11-23 15:06:35 +05:00
|
|
|
}}
|
2022-01-22 12:57:05 +05:00
|
|
|
data={announcement?.body.filter(item => allowedOnPlatform(item.platforms))}
|
|
|
|
|
renderItem={({ item, index }) =>
|
|
|
|
|
renderItem({ item: item, index: index, color: colors[color], inline: true })
|
2021-11-23 15:06:35 +05:00
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
};
|