@magicbell/react-headless
Version:
Hooks to build a notification inbox
51 lines • 1.61 kB
JavaScript
import { postAPI } from '../../lib/ajax.js';
import RemoteRepository from '../repository/RemoteRepository.js';
/**
* Class to interact with the notification API endpoints.
*
* @example
* const repo = new NotificationRepository();
* const notifications = repo.findBy({ unseen: true });
*/
export default class NotificationRepository extends RemoteRepository {
constructor(remotePathOrUrl = '/notifications') {
super(remotePathOrUrl);
}
archive(id) {
const url = `${this.remotePathOrUrl}/${id}/archive`;
return postAPI(url)
.then(() => true)
.catch(() => false);
}
unarchive(id) {
const url = `${this.remotePathOrUrl}/${id}/unarchive`;
return postAPI(url)
.then(() => true)
.catch(() => false);
}
markAsRead(id) {
const url = `${this.remotePathOrUrl}/${id}/read`;
return postAPI(url)
.then(() => true)
.catch(() => false);
}
markAsUnread(id) {
const url = `${this.remotePathOrUrl}/${id}/unread`;
return postAPI(url)
.then(() => true)
.catch(() => false);
}
markAllAsSeen(params) {
const url = `${this.remotePathOrUrl}/seen`;
return postAPI(url, undefined, params)
.then(() => true)
.catch(() => false);
}
markAllAsRead(params) {
const url = `${this.remotePathOrUrl}/read`;
return postAPI(url, undefined, params)
.then(() => true)
.catch(() => false);
}
}
//# sourceMappingURL=NotificationRepository.js.map