mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-28 10:22:38 +03:00
Merge pull request #303 from esteemapp/enhancment/notification
Enhancment/notification
This commit is contained in:
commit
4398e48dfd
@ -10,7 +10,7 @@ export default EStyleSheet.create({
|
|||||||
},
|
},
|
||||||
hasTopBorder: {
|
hasTopBorder: {
|
||||||
borderTopColor: '$borderTopColor',
|
borderTopColor: '$borderTopColor',
|
||||||
borderTopWidth: 1,
|
borderTopWidth: 0.5,
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
fontFamily: '$primaryFont',
|
fontFamily: '$primaryFont',
|
||||||
|
@ -25,6 +25,7 @@ class NotificationView extends PureComponent {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
// TODO: Remove filters from local state.
|
||||||
filters: [
|
filters: [
|
||||||
{ key: 'activities', value: 'ALL ACTIVITIES' },
|
{ key: 'activities', value: 'ALL ACTIVITIES' },
|
||||||
{ key: 'votes', value: 'VOTES' },
|
{ key: 'votes', value: 'VOTES' },
|
||||||
@ -47,31 +48,96 @@ class NotificationView extends PureComponent {
|
|||||||
getActivities(filters[index].key);
|
getActivities(filters[index].key);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
_renderList = (data) => {
|
||||||
const {
|
const { navigateToNotificationRoute } = this.props;
|
||||||
notifications, intl, navigateToNotificationRoute, readAllNotification,
|
|
||||||
} = this.props;
|
|
||||||
const { filters } = this.state;
|
|
||||||
const today = [];
|
|
||||||
const yesterday = [];
|
|
||||||
const thisWeek = [];
|
|
||||||
const thisMonth = [];
|
|
||||||
const olderThenMonth = [];
|
|
||||||
|
|
||||||
notifications.map((item) => {
|
return (
|
||||||
if (isToday(item.timestamp)) {
|
<FlatList
|
||||||
today.push(item);
|
data={data}
|
||||||
} else if (isYesterday(item.timestamp)) {
|
renderItem={({ item }) => (
|
||||||
yesterday.push(item);
|
<NotificationLine
|
||||||
} else if (isThisWeek(item.timestamp)) {
|
notification={item}
|
||||||
thisWeek.push(item);
|
handleOnPressNotification={navigateToNotificationRoute}
|
||||||
} else if (isThisMonth(item.timestamp)) {
|
/>
|
||||||
thisMonth.push(item);
|
)}
|
||||||
} else {
|
keyExtractor={item => item.id}
|
||||||
olderThenMonth.push(item);
|
/>
|
||||||
}
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
_getNotificationsArrays = () => {
|
||||||
|
const { notifications, intl } = this.props;
|
||||||
|
|
||||||
|
if (!notifications && notifications.length < 1) return null;
|
||||||
|
|
||||||
|
const notificationArray = [
|
||||||
|
{
|
||||||
|
title: intl.formatMessage({
|
||||||
|
id: 'notification.recent',
|
||||||
|
}),
|
||||||
|
notifications: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: intl.formatMessage({
|
||||||
|
id: 'notification.yesterday',
|
||||||
|
}),
|
||||||
|
notifications: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: intl.formatMessage({
|
||||||
|
id: 'notification.this_week',
|
||||||
|
}),
|
||||||
|
notifications: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: intl.formatMessage({
|
||||||
|
id: 'notification.this_month',
|
||||||
|
}),
|
||||||
|
notifications: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: intl.formatMessage({
|
||||||
|
id: 'notification.older_then',
|
||||||
|
}),
|
||||||
|
notifications: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
notifications.forEach((item) => {
|
||||||
|
const listIndex = this._getTimeListIndex(item.timestamp);
|
||||||
|
|
||||||
|
notificationArray[listIndex].notifications.push(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return notificationArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
_getTimeListIndex = (timestamp) => {
|
||||||
|
if (isToday(timestamp)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isYesterday(timestamp)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isThisWeek(timestamp)) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isThisMonth(timestamp)) {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 4;
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { readAllNotification } = this.props;
|
||||||
|
const { filters } = this.state;
|
||||||
|
|
||||||
|
const _notifications = this._getNotificationsArrays();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<FilterBar
|
<FilterBar
|
||||||
@ -83,110 +149,14 @@ class NotificationView extends PureComponent {
|
|||||||
onRightIconPress={readAllNotification}
|
onRightIconPress={readAllNotification}
|
||||||
/>
|
/>
|
||||||
<ScrollView style={styles.scrollView}>
|
<ScrollView style={styles.scrollView}>
|
||||||
{today.length > 0 && (
|
{_notifications
|
||||||
<Fragment>
|
&& _notifications.map(
|
||||||
<ContainerHeader
|
item => item.notifications.length > 0 && (
|
||||||
hasSeperator
|
<Fragment key={item.title}>
|
||||||
isBoldTitle
|
<ContainerHeader hasSeperator={ _notifications.indexOf(item) !== 1 } isBoldTitle title={item.title} key={item.title} />
|
||||||
title={intl.formatMessage({
|
{this._renderList(item.notifications)}
|
||||||
id: 'notification.recent',
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
data={today}
|
|
||||||
renderItem={({ item }) => (
|
|
||||||
<NotificationLine
|
|
||||||
notification={item}
|
|
||||||
handleOnPressNotification={navigateToNotificationRoute}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
keyExtractor={item => item.id}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
|
||||||
)}
|
|
||||||
{yesterday.length > 0 && (
|
|
||||||
<Fragment>
|
|
||||||
<ContainerHeader
|
|
||||||
hasSeperator
|
|
||||||
isBoldTitle
|
|
||||||
title={intl.formatMessage({
|
|
||||||
id: 'notification.yesterday',
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
data={yesterday}
|
|
||||||
renderItem={({ item }) => (
|
|
||||||
<NotificationLine
|
|
||||||
notification={item}
|
|
||||||
handleOnPressNotification={navigateToNotificationRoute}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
keyExtractor={item => item.id}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
|
||||||
)}
|
|
||||||
{thisWeek.length > 0 && (
|
|
||||||
<Fragment>
|
|
||||||
<ContainerHeader
|
|
||||||
hasSeperator
|
|
||||||
isBoldTitle
|
|
||||||
title={intl.formatMessage({
|
|
||||||
id: 'notification.this_week',
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
data={thisWeek}
|
|
||||||
renderItem={({ item }) => (
|
|
||||||
<NotificationLine
|
|
||||||
notification={item}
|
|
||||||
handleOnPressNotification={navigateToNotificationRoute}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
keyExtractor={item => item.id}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
|
||||||
)}
|
|
||||||
{thisMonth.length > 0 && (
|
|
||||||
<Fragment>
|
|
||||||
<ContainerHeader
|
|
||||||
hasSeperator
|
|
||||||
isBoldTitle
|
|
||||||
title={intl.formatMessage({
|
|
||||||
id: 'notification.this_month',
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
data={thisMonth}
|
|
||||||
renderItem={({ item }) => (
|
|
||||||
<NotificationLine
|
|
||||||
notification={item}
|
|
||||||
handleOnPressNotification={navigateToNotificationRoute}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
keyExtractor={item => item.id}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
|
||||||
)}
|
|
||||||
{olderThenMonth.length > 0 && (
|
|
||||||
<Fragment>
|
|
||||||
<ContainerHeader
|
|
||||||
hasSeperator
|
|
||||||
isBoldTitle
|
|
||||||
title={intl.formatMessage({
|
|
||||||
id: 'notification.older_then',
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
data={olderThenMonth}
|
|
||||||
renderItem={({ item }) => (
|
|
||||||
<NotificationLine
|
|
||||||
notification={item}
|
|
||||||
handleOnPressNotification={navigateToNotificationRoute}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
keyExtractor={item => item.id}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
),
|
||||||
)}
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
</View>
|
||||||
|
@ -3,13 +3,12 @@ import {
|
|||||||
View, Text, Image, TouchableHighlight,
|
View, Text, Image, TouchableHighlight,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { injectIntl } from 'react-intl';
|
import { injectIntl } from 'react-intl';
|
||||||
import FastImage from 'react-native-fast-image';
|
|
||||||
// Constants
|
// Constants
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
|
import { UserAvatar } from '../../userAvatar';
|
||||||
|
|
||||||
// Styles
|
// Styles
|
||||||
// eslint-disable-next-line
|
|
||||||
import styles from './notificationLineStyles';
|
import styles from './notificationLineStyles';
|
||||||
|
|
||||||
class NotificationLineView extends PureComponent {
|
class NotificationLineView extends PureComponent {
|
||||||
@ -20,31 +19,49 @@ class NotificationLineView extends PureComponent {
|
|||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {};
|
this.state = {
|
||||||
|
isRead: props.notification.read,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Component Life Cycles
|
// Component Life Cycles
|
||||||
|
|
||||||
// Component Functions
|
// Component Functions
|
||||||
|
_handleOnNotificationPress = () => {
|
||||||
|
const { handleOnPressNotification, notification } = this.props;
|
||||||
|
const { isRead } = this.state;
|
||||||
|
|
||||||
|
if (!isRead) this.setState({ isRead: true });
|
||||||
|
|
||||||
|
handleOnPressNotification(notification);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
notification,
|
notification,
|
||||||
intl: { formatMessage },
|
intl: { formatMessage },
|
||||||
handleOnPressNotification,
|
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
const { isRead } = this.state;
|
||||||
|
|
||||||
|
let _title = formatMessage({
|
||||||
|
id: `notification.${notification.type}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (notification.weight) {
|
||||||
|
const _percent = `${(notification.weight / 100).toFixed(0)}% `;
|
||||||
|
|
||||||
|
_title = _percent + _title;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableHighlight onPress={() => handleOnPressNotification(notification)}>
|
<TouchableHighlight onPress={() => this._handleOnNotificationPress()}>
|
||||||
<View
|
<View
|
||||||
key={Math.random()}
|
key={Math.random()}
|
||||||
style={[styles.notificationWrapper, !notification.read && styles.isNewNotification]}
|
style={[styles.notificationWrapper, !isRead && styles.isNewNotification]}
|
||||||
>
|
>
|
||||||
<FastImage
|
<UserAvatar
|
||||||
|
username={notification.source}
|
||||||
style={[styles.avatar, !notification.avatar && styles.hasNoAvatar]}
|
style={[styles.avatar, !notification.avatar && styles.hasNoAvatar]}
|
||||||
source={{
|
|
||||||
uri: `https://steemitimages.com/u/${notification.source}/avatar/small`,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<View style={styles.body}>
|
<View style={styles.body}>
|
||||||
<View style={styles.titleWrapper}>
|
<View style={styles.titleWrapper}>
|
||||||
@ -52,11 +69,7 @@ class NotificationLineView extends PureComponent {
|
|||||||
{notification.source}
|
{notification.source}
|
||||||
{' '}
|
{' '}
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={styles.title}>
|
<Text style={styles.title}>{_title}</Text>
|
||||||
{formatMessage({
|
|
||||||
id: `notification.${notification.type}`,
|
|
||||||
})}
|
|
||||||
</Text>
|
|
||||||
</View>
|
</View>
|
||||||
{notification.description && (
|
{notification.description && (
|
||||||
<Text numberOfLines={1} style={styles.description}>
|
<Text numberOfLines={1} style={styles.description}>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"fill_order": "Fill Order"
|
"fill_order": "Fill Order"
|
||||||
},
|
},
|
||||||
"notification": {
|
"notification": {
|
||||||
"vote": "voted to your post",
|
"vote": "likes your post",
|
||||||
"unvote": "unvoted your post",
|
"unvote": "unvoted your post",
|
||||||
"reply": "replied to your post",
|
"reply": "replied to your post",
|
||||||
"mention": "mentioned you",
|
"mention": "mentioned you",
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
"fill_order": "Fill Order"
|
"fill_order": "Fill Order"
|
||||||
},
|
},
|
||||||
"notification": {
|
"notification": {
|
||||||
"vote": "gönderini oyladı",
|
"vote": "beğendi",
|
||||||
"unvote": "gonderini yukarı yönde oyladı",
|
"unvote": "gonderini aşaği yönde oyladı",
|
||||||
"reply": "gönderine cevap verdi",
|
"reply": "gönderine cevap verdi",
|
||||||
"mention": "seni etiketledi",
|
"mention": "seni etiketledi",
|
||||||
"follow": "seni takip etti",
|
"follow": "seni takip etti",
|
||||||
|
@ -246,7 +246,9 @@ export const getPosts = async (by, query, user) => {
|
|||||||
try {
|
try {
|
||||||
let posts = await client.database.getDiscussions(by, query);
|
let posts = await client.database.getDiscussions(by, query);
|
||||||
|
|
||||||
|
if (posts) {
|
||||||
posts = await parsePosts(posts, user);
|
posts = await parsePosts(posts, user);
|
||||||
|
}
|
||||||
return posts;
|
return posts;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
|
@ -22,7 +22,7 @@ export const parsePost = (post, currentUserName, isSummary = false) => {
|
|||||||
_post.active_votes.sort((a, b) => b.rshares - a.rshares);
|
_post.active_votes.sort((a, b) => b.rshares - a.rshares);
|
||||||
|
|
||||||
_post.body = markDown2Html(post.body);
|
_post.body = markDown2Html(post.body);
|
||||||
if (isSummary) _post.summary = getPostSummary(post.body, 150);
|
_post.summary = getPostSummary(post.body, 150);
|
||||||
|
|
||||||
if (currentUserName) {
|
if (currentUserName) {
|
||||||
_post.is_voted = isVoted(_post.active_votes, currentUserName);
|
_post.is_voted = isVoted(_post.active_votes, currentUserName);
|
||||||
|
Loading…
Reference in New Issue
Block a user