Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(sidebar): add enable notifications button (#2728)

Evan Hutnik6075176816ff
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.tsx b/js/app/packages/app/component/app-sidebar/sidebar.tsx
index fda557b3f7..3d7d7db1b2 100644
--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx
+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx
@@ -55,6 +55,8 @@ import {
} from '@app/component/app-sidebar/invite-modal';
import { ENABLE_CALLS } from '@core/constant/featureFlags';
import { AnimatedCallIcon } from '@macro-icons/wide/animating/call';
+import BellIcon from '@icon/regular/bell.svg';
+import { useNotificationSettings } from '@notifications';
interface SidebarItem {
id: ListView;
@@ -361,6 +363,19 @@ export const AppSidebar = (props: AppSidebarProps) => {
const analytics = useAnalytics();
const layout = useSplitLayout();
const { toggleSettings } = useSettingsState();
+ const notificationSettings = useNotificationSettings();
+
+ const showEnableNotifications = () =>
+ notificationSettings.isSupported && notificationSettings.canPrompt();
+
+ const handleEnableNotifications = async () => {
+ if (!notificationSettings.isSupported) return;
+ try {
+ await notificationSettings.toggle(true);
+ } catch (error) {
+ console.error('Failed to enable notifications:', error);
+ }
+ };
const [hotkeyVisible, setHotkeyVisible] = createSignal(false);
@@ -516,6 +531,15 @@ export const AppSidebar = (props: AppSidebarProps) => {
</div>
<div class=" w-full px-2 flex flex-col">
+ <Show when={showEnableNotifications()}>
+ <SidebarActionButton
+ label="Enable Notifications"
+ isSlim={isSlim}
+ onClick={handleEnableNotifications}
+ icon={() => <BellIcon class="size-4" />}
+ />
+ </Show>
+
<SidebarActionButton
label="Invite"
isSlim={isSlim}
diff --git a/js/app/packages/notifications/notification-settings.ts b/js/app/packages/notifications/notification-settings.ts
index c55cb9e348..42d047647b 100644
--- a/js/app/packages/notifications/notification-settings.ts
+++ b/js/app/packages/notifications/notification-settings.ts
@@ -28,12 +28,10 @@ function createIsEnabled(
return () => permission.latest === 'granted';
}
-function createShouldPrompt(
- permission: Resource<NotificationPermission | UiDisabled>,
- isDismissed: Accessor<boolean>
+function createCanPrompt(
+ permission: Resource<NotificationPermission | UiDisabled>
): Accessor<boolean> {
return () => {
- if (isDismissed()) return false;
const p = permission();
return (
p !== undefined &&
@@ -44,6 +42,13 @@ function createShouldPrompt(
};
}
+function createShouldPrompt(
+ canPrompt: Accessor<boolean>,
+ isDismissed: Accessor<boolean>
+): Accessor<boolean> {
+ return () => canPrompt() && !isDismissed();
+}
+
function createToggle(
state: PlatformNotificationState
): (enabled: boolean) => Promise<void> {
@@ -62,9 +67,15 @@ export type SupportedNotificationSettings = {
isSupported: true;
/** Whether notifications are currently enabled (granted and not disabled in UI) */
isEnabled: Accessor<boolean>;
+ /**
+ * Whether the user currently has a path to enable notifications.
+ * Returns false while the permission resource is still loading, and
+ * false when permission is granted, denied, or disabled in the UI.
+ */
+ canPrompt: Accessor<boolean>;
/** Toggle notifications on/off */
toggle: (enabled: boolean) => Promise<void>;
- /** Whether the enable prompt should be shown (permission not yet decided, not dismissed) */
+ /** Whether the enable prompt should be shown (can prompt and not dismissed) */
shouldPrompt: Accessor<boolean>;
/** Dismiss the enable prompt */
dismissPrompt: () => void;
@@ -84,11 +95,14 @@ export function useNotificationSettings(): NotificationSettings {
const [isDismissed, dismissPrompt] =
createPersistedDismissed(PROMPT_DISMISSED_KEY);
+ const canPrompt = createCanPrompt(state.permission);
+
return {
isSupported: true,
isEnabled: createIsEnabled(state.permission),
+ canPrompt,
toggle: createToggle(state),
- shouldPrompt: createShouldPrompt(state.permission, isDismissed),
+ shouldPrompt: createShouldPrompt(canPrompt, isDismissed),
dismissPrompt,
};
}