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

alkem-io / client-web / #9533

05 Dec 2024 02:27PM UTC coverage: 5.947%. First build
#9533

Pull #7254

travis-ci

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

194 of 10628 branches covered (1.83%)

Branch coverage included in aggregate %.

40 of 177 new or added lines in 15 files covered. (22.6%)

1532 of 18394 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 {
8
  isEnabled: boolean;
9
  isOpen: boolean;
10
  setIsOpen: (isOpen: boolean) => void;
NEW
11
  selectedFilter: NotificationFilterType;
×
12
  setSelectedFilter: (filter: NotificationFilterType) => void;
NEW
13
}
×
NEW
14

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

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

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

×
29
  // Initialize filter from localStorage or default to All
30
  const [selectedFilter, setSelectedFilter] = useState<NotificationFilterType>(() => {
NEW
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