analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
127 lines (119 loc) • 4.29 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunk24ICWSQQjs = require('./chunk-24ICWSQQ.js');
var _chunkBXORK7GMjs = require('./chunk-BXORK7GM.js');
// src/hooks/useNotifications.ts
var _react = require('react');
var createUseNotifications = (apiClient) => {
const useNotificationStore = _chunk24ICWSQQjs.createUseNotificationStore.call(void 0, apiClient);
return () => {
const {
notifications,
unreadCount,
loading,
error,
hasMore,
currentPage,
fetchNotifications,
fetchUnreadCount,
markAsRead,
markAllAsRead,
deleteNotification,
clearNotifications,
resetError,
getGroupedNotifications
} = useNotificationStore();
const handleNavigate = _react.useCallback.call(void 0,
(entityType, entityId, onAfterNavigate) => {
if (entityType) {
switch (entityType.toUpperCase()) {
case "ACTIVITY" /* ACTIVITY */:
if (entityId) {
globalThis.location.href = `/conteudo/atividades/${entityId}`;
}
break;
case "RECOMMENDEDCLASS" /* RECOMMENDEDCLASS */:
globalThis.location.href = `/plano/consultar`;
break;
default:
break;
}
_optionalChain([onAfterNavigate, 'optionalCall', _ => _()]);
}
},
[]
);
const getActionLabel = _react.useCallback.call(void 0,
(entityType) => {
if (!entityType) return "Ver mais";
switch (entityType.toUpperCase()) {
case "ACTIVITY" /* ACTIVITY */:
return "Ver atividade";
case "RECOMMENDEDCLASS" /* RECOMMENDEDCLASS */:
return "Ver meta";
default:
return void 0;
}
},
[]
);
const markAsReadAndNavigate = _react.useCallback.call(void 0,
async (id, entityType, entityId, onAfterNavigate) => {
await markAsRead(id);
if (entityType && entityId) {
handleNavigate(entityType, entityId, onAfterNavigate);
}
},
[markAsRead, handleNavigate]
);
const refreshNotifications = _react.useCallback.call(void 0, async () => {
resetError();
await fetchNotifications();
}, [resetError, fetchNotifications]);
const formatNotification = _react.useCallback.call(void 0,
(notification) => ({
...notification,
time: _chunkBXORK7GMjs.formatTimeAgo.call(void 0, notification.createdAt),
entityType: notification.entityType || void 0,
entityId: notification.entityId || void 0
}),
[]
);
const getFormattedGroupedNotifications = _react.useCallback.call(void 0, () => {
const groups = getGroupedNotifications();
return groups.map((group) => ({
...group,
notifications: group.notifications.map(formatNotification)
}));
}, [getGroupedNotifications, formatNotification]);
return {
// State
notifications,
unreadCount,
loading,
error,
hasMore,
currentPage,
// Actions
fetchNotifications,
fetchUnreadCount,
markAsRead,
markAllAsRead,
deleteNotification,
clearNotifications,
resetError,
markAsReadAndNavigate,
refreshNotifications,
// Navigation
handleNavigate,
// Helpers
getActionLabel,
getGroupedNotifications,
getFormattedGroupedNotifications
};
};
};
var createNotificationsHook = (apiClient) => {
return createUseNotifications(apiClient);
};
exports.createUseNotifications = createUseNotifications; exports.createNotificationsHook = createNotificationsHook;
//# sourceMappingURL=chunk-UADGRG6L.js.map