react-notify-sdk 1.0.37 → 1.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ export const FadeWrapper = styled("div") `
4
4
  opacity: ${(props) => (props.visible ? 1 : 0)};
5
5
  animation: ${(props) => (props.visible ? fadeIn : fadeOut)} 0.3s ease forwards;
6
6
  transition: opacity 0.3s ease;
7
- position: absolute;
7
+ position: fixed;
8
8
  width: ${(props) => props.device === 'Mobile' ? '95%' : props.device === 'Tablet' ? '420px' : '420px'};
9
9
  top: ${(props) => props.message?.position === 'top' ? '24px' : ''};
10
10
  bottom: ${(props) => props.message?.position === 'bottom' ? '24px' : ''};
@@ -18,16 +18,40 @@ const routeMatches = (pattern, path) => {
18
18
  return false;
19
19
  }
20
20
  };
21
- export const FeatureMessageProvider = ({ projectKey,
22
- //className,
23
- //style,
24
- //disableDefaultStyles = true,
25
- }) => {
21
+ export const FeatureMessageProvider = ({ projectKey, }) => {
26
22
  const [message, setMessage] = useState(null);
27
23
  const [visible, setVisible] = useState(false);
24
+ const [pathname, setPathname] = useState(() => typeof window !== 'undefined' ? window.location.pathname : '');
28
25
  const device = useDeviceDetection();
29
26
  // Create supabase client with project key header
30
27
  const supabaseClient = getSupabaseClient(projectKey);
28
+ // Effect to track pathname changes
29
+ useEffect(() => {
30
+ if (typeof window === 'undefined')
31
+ return;
32
+ const updatePathname = () => {
33
+ setPathname(window.location.pathname);
34
+ };
35
+ // Listen for browser back/forward navigation
36
+ window.addEventListener('popstate', updatePathname);
37
+ // Listen for programmatic navigation (pushState/replaceState)
38
+ const originalPushState = window.history.pushState;
39
+ const originalReplaceState = window.history.replaceState;
40
+ window.history.pushState = function (...args) {
41
+ originalPushState.apply(window.history, args);
42
+ updatePathname();
43
+ };
44
+ window.history.replaceState = function (...args) {
45
+ originalReplaceState.apply(window.history, args);
46
+ updatePathname();
47
+ };
48
+ return () => {
49
+ window.removeEventListener('popstate', updatePathname);
50
+ window.history.pushState = originalPushState;
51
+ window.history.replaceState = originalReplaceState;
52
+ };
53
+ }, []);
54
+ // Your main effect - now uses the reactive pathname state
31
55
  useEffect(() => {
32
56
  if (typeof window === 'undefined')
33
57
  return; // Skip on server
@@ -36,12 +60,10 @@ export const FeatureMessageProvider = ({ projectKey,
36
60
  .from('feature_messages')
37
61
  .select('*')
38
62
  .eq('project_key', projectKey)
39
- .eq('route', window.location.pathname)
63
+ .eq('route', pathname)
40
64
  .eq('is_active', true)
41
65
  .order('created_at', { ascending: false });
42
- //.limit(1)
43
- //.single();
44
- const match = data?.find((msg) => routeMatches(msg.route, window.location.pathname));
66
+ const match = data?.find((msg) => routeMatches(msg.route, pathname));
45
67
  if (match) {
46
68
  setMessage(match);
47
69
  setVisible(true); // Fade in
@@ -61,7 +83,7 @@ export const FeatureMessageProvider = ({ projectKey,
61
83
  table: 'feature_messages',
62
84
  }, (payload) => {
63
85
  const msg = payload.new;
64
- if (msg.project_key === projectKey && msg.is_active && routeMatches(msg.route, window.location.pathname)) {
86
+ if (msg.project_key === projectKey && msg.is_active && routeMatches(msg.route, pathname)) {
65
87
  setMessage(msg);
66
88
  setVisible(true);
67
89
  }
@@ -74,9 +96,8 @@ export const FeatureMessageProvider = ({ projectKey,
74
96
  return () => {
75
97
  supabaseClient.removeChannel(subscription);
76
98
  };
77
- }, [window.location.pathname, projectKey]);
99
+ }, [pathname, projectKey]);
78
100
  if (!message)
79
101
  return null;
80
- //const defaultClasses = `absolute ${message?.position}-6 left-1/2 transform -translate-x-1/2 z-20 w-full md:w-[${message?.width}%] px-3 py-1 bg-[${message?.backgroundColor}] border border-[${message?.borderColor}] text-[${message?.textColor}] rounded-lg shadow`;
81
102
  return (_jsx(FadeWrapper, { visible: visible, device: device, message: message, children: _jsx(FeatureMessage, { message: message }) }));
82
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-notify-sdk",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "SDK for displaying real-time route-specific messages in React apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",