This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
forked from irislib/iris-messenger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Better navigation
- Loading branch information
Showing
6 changed files
with
110 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { html } from 'htm/preact'; | ||
import State from 'iris-lib/src/State'; | ||
import Identicon from '../components/Identicon'; | ||
import Button from '../components/basic/Button'; | ||
import {translate as t} from '../translations/Translation'; | ||
import Name from '../components/Name'; | ||
import NotificationTools from "iris-lib/src/Notifications"; | ||
import util from "iris-lib/src/util"; | ||
import { Component } from 'preact'; | ||
const PAGE_SIZE = 10; | ||
|
||
export default class NotificationsComponent extends Component{ | ||
notifications = {}; | ||
class = 'public-messages-view'; | ||
state = { | ||
displayCount: PAGE_SIZE | ||
} | ||
|
||
componentDidMount() { | ||
NotificationTools.changeUnseenNotificationCount(0); | ||
State.local.get('notifications').map( | ||
(notification, time) => { | ||
if (notification) { | ||
this.notifications[time] = notification; | ||
NotificationTools.getNotificationText(notification).then(text => { | ||
this.notifications[time].text = text; | ||
this.setState({}); | ||
}); | ||
} else { | ||
delete this.notifications[time]; | ||
} | ||
this.setState({d:new Date().toISOString()}); | ||
} | ||
); | ||
} | ||
|
||
shouldComponentUpdate() { | ||
return true; | ||
} | ||
|
||
render() { | ||
const displayCount = this.state.displayCount; | ||
const notificationKeys = Object.keys(this.notifications).sort().reverse(); | ||
return html` | ||
<div class="centered-container" style="margin-bottom: 15px;"> | ||
<h3>${t('notifications')}</h3> | ||
${Object.keys(this.notifications).length === 0 ? html` | ||
<p> ${t('no_notifications_yet')}</p> | ||
`:''} | ||
${notificationKeys.slice(0, this.state.displayCount).map(k => { | ||
const notification = this.notifications[k]; | ||
return html` | ||
<div class="msg" key=${(notification.time||'') + (notification.from||'') + (notification.target||'')}> | ||
<div class="msg-content"> | ||
<div class="msg-sender"> | ||
<a class="msg-sender-link" href="/profile/${notification.from}"> | ||
<${Identicon} str=${notification.from} width=30 />${' '} | ||
<small class="msgSenderName"><${Name} pub=${notification.from} /></small> | ||
</a> | ||
</div> | ||
${notification.text || ''} | ||
<div class="below-text"> | ||
<div class="time">${util.formatDate(new Date(notification.time))}</div><br/> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
})} | ||
${displayCount < notificationKeys.length ? html` | ||
<div> | ||
<${Button} onClick=${() => this.setState({displayCount: displayCount + PAGE_SIZE})}> | ||
${t('show_more')} | ||
<//> | ||
</div> | ||
` : ''} | ||
</div> | ||
`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,9 @@ | ||
import { html } from 'htm/preact'; | ||
import State from 'iris-lib/src/State'; | ||
import Identicon from '../components/Identicon'; | ||
import Button from '../components/basic/Button'; | ||
import {translate as t} from '../translations/Translation'; | ||
import Name from '../components/Name'; | ||
import View from './View'; | ||
import NotificationTools from "iris-lib/src/Notifications"; | ||
import util from "iris-lib/src/util"; | ||
const PAGE_SIZE = 10; | ||
import NotificationsComponent from '../components/NotificationsComponent'; | ||
|
||
export default class Notifications extends View { | ||
notifications = {}; | ||
class = 'public-messages-view'; | ||
state = { | ||
displayCount: PAGE_SIZE | ||
} | ||
|
||
componentDidMount() { | ||
NotificationTools.changeUnseenNotificationCount(0); | ||
State.local.get('notifications').map(this.sub( | ||
(notification, time) => { | ||
if (notification) { | ||
this.notifications[time] = notification; | ||
NotificationTools.getNotificationText(notification).then(text => { | ||
this.notifications[time].text = text; | ||
this.setState({}); | ||
}); | ||
} else { | ||
delete this.notifications[time]; | ||
} | ||
this.setState({d:new Date().toISOString()}); | ||
} | ||
)); | ||
} | ||
|
||
shouldComponentUpdate() { | ||
return true; | ||
} | ||
|
||
renderView() { | ||
const displayCount = this.state.displayCount; | ||
const notificationKeys = Object.keys(this.notifications).sort().reverse(); | ||
return html` | ||
<div class="centered-container" style="margin-bottom: 15px;"> | ||
<h3>${t('notifications')}</h3> | ||
${Object.keys(this.notifications).length === 0 ? html` | ||
<p> ${t('no_notifications_yet')}</p> | ||
`:''} | ||
${notificationKeys.slice(0, this.state.displayCount).map(k => { | ||
const notification = this.notifications[k]; | ||
return html` | ||
<div class="msg" key=${(notification.time||'') + (notification.from||'') + (notification.target||'')}> | ||
<div class="msg-content"> | ||
<div class="msg-sender"> | ||
<a class="msg-sender-link" href="/profile/${notification.from}"> | ||
<${Identicon} str=${notification.from} width=30 />${' '} | ||
<small class="msgSenderName"><${Name} pub=${notification.from} /></small> | ||
</a> | ||
</div> | ||
${notification.text || ''} | ||
<div class="below-text"> | ||
<div class="time">${util.formatDate(new Date(notification.time))}</div><br/> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
})} | ||
${displayCount < notificationKeys.length ? html` | ||
<div> | ||
<${Button} onClick=${() => this.setState({displayCount: displayCount + PAGE_SIZE})}> | ||
${t('show_more')} | ||
<//> | ||
</div> | ||
` : ''} | ||
</div> | ||
`; | ||
return (<NotificationsComponent />); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters