2021-11-23 15:06:35 +05:00
|
|
|
import React from 'react';
|
|
|
|
|
import {FlatList, View} from 'react-native';
|
|
|
|
|
import {useTracked} from '../../provider';
|
|
|
|
|
import {useMessageStore, useSelectionStore} from '../../provider/stores';
|
|
|
|
|
import {Button} from '../Button';
|
|
|
|
|
import {allowedOnPlatform, renderItem} from './functions';
|
|
|
|
|
|
|
|
|
|
export const Announcement = ({color}) => {
|
|
|
|
|
const [state] = useTracked();
|
|
|
|
|
const colors = state.colors;
|
|
|
|
|
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%'
|
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'
|
2021-11-23 15:06:35 +05:00
|
|
|
}}>
|
2021-11-23 19:24:53 +05:00
|
|
|
<Button
|
|
|
|
|
type="errorShade"
|
|
|
|
|
icon="close"
|
|
|
|
|
height={null}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
remove(announcement.id);
|
|
|
|
|
}}
|
|
|
|
|
iconSize={22}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 0,
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
top: 10,
|
|
|
|
|
right: 10
|
|
|
|
|
}}
|
|
|
|
|
/>
|
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
|
|
|
}}
|
|
|
|
|
data={announcement?.body.filter(item =>
|
2021-12-02 21:21:00 +05:00
|
|
|
allowedOnPlatform(item.platforms)
|
2021-11-23 15:06:35 +05:00
|
|
|
)}
|
|
|
|
|
renderItem={({item, index}) =>
|
2021-11-23 19:24:53 +05:00
|
|
|
renderItem({item: item, index: index, color: colors[color],inline:true})
|
2021-11-23 15:06:35 +05:00
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
};
|