Skip to content

Commit

Permalink
feat: use highSignalNotificationFilter to api (#3588)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Aug 20, 2023
1 parent 58135d9 commit dd052c1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
32 changes: 29 additions & 3 deletions apps/web/src/components/Notification/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import ToggleWithHelper from '@components/Shared/ToggleWithHelper';
import { BellIcon, CogIcon, ColorSwatchIcon } from '@heroicons/react/outline';
import { PREFERENCES_WORKER_URL } from '@lenster/data/constants';
import { Localstorage } from '@lenster/data/storage';
import { NOTIFICATION } from '@lenster/data/tracking';
import { Modal, Tooltip } from '@lenster/ui';
import { Leafwatch } from '@lib/leafwatch';
import { t } from '@lingui/macro';
import axios from 'axios';
import type { FC } from 'react';
import { useState } from 'react';
import { toast } from 'react-hot-toast';
import { useAppStore } from 'src/store/app';
import { usePreferencesStore } from 'src/store/preferences';

const Settings: FC = () => {
const currentProfile = useAppStore((state) => state.currentProfile);
const highSignalNotificationFilter = usePreferencesStore(
(state) => state.highSignalNotificationFilter
);
Expand All @@ -16,6 +24,26 @@ const Settings: FC = () => {
const [showNotificationSettings, setShowNotificationSettings] =
useState(false);

const toggleHighSignalNotificationFilter = () => {
toast.promise(
axios.post(`${PREFERENCES_WORKER_URL}/update`, {
id: currentProfile?.id,
highSignalNotificationFilter: !highSignalNotificationFilter,
accessToken: localStorage.getItem(Localstorage.AccessToken)
}),
{
loading: t`Updating notification settings...`,
success: () => {
setHighSignalNotificationFilter(!highSignalNotificationFilter);
Leafwatch.track(NOTIFICATION.TOGGLE_HIGH_SIGNAL_NOTIFICATION_FILTER);

return t`Notification settings updated`;
},
error: t`Error updating notification settings`
}
);
};

return (
<>
<button
Expand All @@ -35,9 +63,7 @@ const Settings: FC = () => {
<div className="p-5">
<ToggleWithHelper
on={highSignalNotificationFilter}
setOn={() => {
setHighSignalNotificationFilter(!highSignalNotificationFilter);
}}
setOn={toggleHighSignalNotificationFilter}
heading={t`Signal filter`}
description={t`Turn on high-signal notification filter`}
icon={<ColorSwatchIcon className="h-4 w-4" />}
Expand Down
4 changes: 3 additions & 1 deletion packages/data/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export const PUBLICATION = {
};

export const NOTIFICATION = {
SWITCH_NOTIFICATION_TAB: 'Switch notifications tab'
SWITCH_NOTIFICATION_TAB: 'Switch notifications tab',
TOGGLE_HIGH_SIGNAL_NOTIFICATION_FILTER:
'Toggle high signal notification filter'
};

export const HOME = {
Expand Down
12 changes: 9 additions & 3 deletions packages/workers/preferences/src/handlers/updatePreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ExtensionRequest = {
isGardener?: boolean;
isTrustedMember?: boolean;
isVerified?: boolean;
highSignalNotificationFilter?: boolean;
updateByAdmin?: boolean;
accessToken: string;
};
Expand All @@ -27,6 +28,7 @@ const validationSchema = object({
isGardener: boolean().optional(),
isTrustedMember: boolean().optional(),
isVerified: boolean().optional(),
highSignalNotificationFilter: boolean().optional(),
updateByAdmin: boolean().optional(),
accessToken: string().regex(Regex.accessToken)
});
Expand All @@ -50,6 +52,7 @@ export default async (request: IRequest, env: Env) => {
isTrustedMember,
updateByAdmin,
isVerified,
highSignalNotificationFilter,
accessToken
} = body as ExtensionRequest;

Expand Down Expand Up @@ -82,7 +85,8 @@ export default async (request: IRequest, env: Env) => {
is_gardener: isGardener,
is_trusted_member: isTrustedMember,
is_verified: isVerified
})
}),
high_signal_notification_filter: highSignalNotificationFilter
})
.select()
.single();
Expand All @@ -91,8 +95,10 @@ export default async (request: IRequest, env: Env) => {
throw error;
}

// Clear cache in Cloudflare KV
await env.PREFERENCES.delete('verified-list');
if (updateByAdmin) {
// Clear cache in Cloudflare KV
await env.PREFERENCES.delete('verified-list');
}

return response({ success: true, result: data });
} catch (error) {
Expand Down

2 comments on commit dd052c1

@vercel
Copy link

@vercel vercel bot commented on dd052c1 Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

prerender – ./apps/prerender

prerender-lenster.vercel.app
prerender-git-main-lenster.vercel.app
prerender.lenster.xyz

@vercel
Copy link

@vercel vercel bot commented on dd052c1 Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./apps/web

lenster.vercel.app
web-lenster.vercel.app
lenster.xyz
web-git-main-lenster.vercel.app

Please sign in to comment.