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

alkem-io / client-web / #9517

03 Dec 2024 05:01PM UTC coverage: 5.941%. First build
#9517

Pull #7254

travis-ci

Pull Request #7254: In-app Notifications v1 for Beta Testers

194 of 10652 branches covered (1.82%)

Branch coverage included in aggregate %.

40 of 178 new or added lines in 15 files covered. (22.47%)

1532 of 18398 relevant lines covered (8.33%)

0.19 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 { useCurrentUserContext } from '@/domain/community/userCurrent/useCurrentUserContext';
2
import { createContext, useState, useContext, ReactNode, useEffect } from 'react';
3
import { NotificationFilterType } from './notificationFilters';
4

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

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

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

NEW
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
      console.error('Failed to read notification filter from localStorage:', error);
38
    }
39
    return NotificationFilterType.All;
40
  });
41

42
  // Persist filter changes to localStorage
43
  useEffect(() => {
44
    try {
45
      localStorage.setItem(NOTIFICATION_FILTER_STORAGE_KEY, selectedFilter);
46
    } catch (error) {
47
      console.error('Failed to save notification filter to localStorage:', error);
48
    }
49
  }, [selectedFilter]);
50

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

54
  return (
55
    <InAppNotifications value={{ isEnabled, isOpen, setIsOpen, selectedFilter, setSelectedFilter }}>
56
      {children}
57
    </InAppNotifications>
58
  );
59
};
60

61
export const useInAppNotificationsContext = () => {
62
  const context = useContext(InAppNotifications);
63

64
  if (!context) {
65
    throw new Error('useInAppNotificationsContext must be used within a InAppNotificationsProvider');
66
  }
67

68
  return context;
69
};
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