• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alkem-io / client-web / #10022

24 Jan 2025 09:50AM UTC coverage: 5.689%. First build
#10022

Pull #7423

travis-ci

Pull Request #7423: Role setsv2

188 of 11016 branches covered (1.71%)

Branch coverage included in aggregate %.

346 of 1599 new or added lines in 92 files covered. (21.64%)

1517 of 18956 relevant lines covered (8.0%)

0.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/inAppNotifications/InAppNotificationsContext.tsx
1
import { createContext, type ReactNode, useContext, useEffect, useState } from 'react';
2
import { useCurrentUserContext } from '@/domain/community/userCurrent/useCurrentUserContext';
3
import { NotificationFilterType } from './notificationFilters';
4

5
const NOTIFICATION_FILTER_STORAGE_KEY = 'alkemio.notifications.filter';
6

7
interface InAppNotificationsContextProps {
8
  isEnabled: boolean;
9
  isOpen: boolean;
10
  setIsOpen: (isOpen: boolean) => void;
11
  selectedFilter: NotificationFilterType;
×
12
  setSelectedFilter: (filter: NotificationFilterType) => void;
13
}
×
14

×
15
const defaultState: InAppNotificationsContextProps = {
×
16
  isEnabled: false,
17
  isOpen: false,
×
NEW
18
  setIsOpen: () => {},
×
19
  selectedFilter: NotificationFilterType.All,
20
  setSelectedFilter: () => {},
21
};
×
22

23
const InAppNotifications = createContext<InAppNotificationsContextProps>(defaultState);
24

×
25
export const InAppNotificationsProvider = ({ children }: { children: ReactNode }) => {
×
26
  const { userModel } = useCurrentUserContext();
27
  const [isOpen, setIsOpen] = useState(false);
×
28

×
29
  // Initialize filter from localStorage or default to All
30
  const [selectedFilter, setSelectedFilter] = useState<NotificationFilterType>(() => {
31
    try {
×
32
      const stored = localStorage.getItem(NOTIFICATION_FILTER_STORAGE_KEY);
33
      if (stored && Object.values(NotificationFilterType).includes(stored as NotificationFilterType)) {
34
        return stored as NotificationFilterType;
35
      }
36
    } catch (_error) {}
37
    return NotificationFilterType.All;
38
  });
39

40
  // Persist filter changes to localStorage
41
  useEffect(() => {
42
    try {
43
      localStorage.setItem(NOTIFICATION_FILTER_STORAGE_KEY, selectedFilter);
44
    } catch (_error) {}
45
  }, [selectedFilter]);
46

47
  // let's keep that logic in case we want to enable/disable the feature in the future
48
  const isEnabled = Boolean(userModel?.id);
49

50
  return (
51
    <InAppNotifications value={{ isEnabled, isOpen, setIsOpen, selectedFilter, setSelectedFilter }}>
52
      {children}
53
    </InAppNotifications>
54
  );
55
};
56

57
export const useInAppNotificationsContext = () => {
58
  const context = useContext(InAppNotifications);
59

60
  if (!context) {
61
    throw new Error('useInAppNotificationsContext must be used within a InAppNotificationsProvider');
62
  }
63

64
  return context;
65
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc