Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Combination of 3 PR's #2724

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a6577d8
CW-some-stream-disappear Optimized FeedItem component. FIxed conditio…
pvm-code Aug 1, 2024
0e0bde0
CW-some-stream-disappear Fixed Render fewer hooks issue
pvm-code Aug 5, 2024
c14a3be
CW-some-stream-disappear Added names to components for better debugging
pvm-code Aug 6, 2024
b90ebbf
CW-some-stream-disappear Added commonId related logic for Feed
pvm-code Aug 7, 2024
e0e046c
CW-mobile-performance Added memoization for ProjectFeedItem
pvm-code Aug 8, 2024
795445b
CW-mobile-performance Added memoization for FeedCard
pvm-code Aug 8, 2024
66c84cf
CW-mobile-performance Added useMemo for lastMessages and menuItems
pvm-code Aug 8, 2024
5c9a860
CW-mobile-performance Added memo for CommonFeed
pvm-code Aug 8, 2024
c6cbf9d
CW-mobile-performance Fix type issue
pvm-code Aug 8, 2024
5e0d1c5
CW-mobile-performance Optimize FeedLayout
pvm-code Aug 8, 2024
c38e291
CW-mobile-performance Added memo for TreeItemTrigger and useMenuItems
pvm-code Aug 8, 2024
a5d19af
CW-mobile-performance Fix TreeItemTrigger component
pvm-code Aug 9, 2024
fb6414d
CW-mobile-performance Optimize components
pvm-code Aug 9, 2024
51142e5
CW-mobile-perfromance Remove unnecessary libraries
pvm-code Aug 12, 2024
d7792d4
CW-mobile-performance Fix jest config
pvm-code Aug 12, 2024
d9aa6e8
CW-mobile-performance Fix words func call
pvm-code Aug 12, 2024
9fecc76
CW-mobile-performance Fix eslint
pvm-code Aug 12, 2024
8b4d4af
CW-mobile-performance Added lodash-es types
pvm-code Aug 12, 2024
dbcf4b6
Revert "CW-mobile-performance Added lodash-es types"
pvm-code Aug 12, 2024
218e362
Revert "CW-mobile-performance Fix eslint"
pvm-code Aug 12, 2024
5813f1b
Revert "CW-mobile-performance Fix words func call"
pvm-code Aug 12, 2024
9d245d0
Revert "CW-mobile-performance Fix jest config"
pvm-code Aug 12, 2024
2be85e8
Revert "CW-mobile-perfromance Remove unnecessary libraries"
pvm-code Aug 12, 2024
cd759f1
CW-firebase-messaging-for-web Added push notification config for web
pvm-code Aug 14, 2024
6b7537e
CW-firebase-messaging-for-web Update settings
pvm-code Aug 15, 2024
92e2dfc
CW-firebase-messaging-for-web Updated config
pvm-code Aug 15, 2024
a71b7ca
CW-firebase-messaging-for-web Fixed env issue for service worker
pvm-code Aug 16, 2024
f18787b
Merge branch 'CW-mobile-performance' into CW-latest-PRs
pvm-code Aug 16, 2024
6e5e07d
Merge branch 'CW-firebase-messaging-for-web' into CW-latest-PRs
pvm-code Aug 16, 2024
63c89a7
Merge branch 'CW-some-stream-disappear' into CW-latest-PRs
pvm-code Aug 16, 2024
de573f6
CW-latest-PRs Fix service worker name
pvm-code Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions public/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* eslint-disable */
// firebase-messaging-sw.js
importScripts(
"https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js",
);
importScripts(
"https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging-compat.js",
);

const ENV = {
LOCAL: "http://localhost:3000",
DEV: "https://web-dev.common.io",
STAGE: "https://web-staging.common.io",
PRODUCTION: "https://common.io",
};

const FIREBASE_CONFIG_ENV = {
DEV: {
apiKey: "AIzaSyDbTFuksgOkIVWDiFe_HG7-BE8X6Dwsg-0",
authDomain: "common-dev-34b09.firebaseapp.com",
databaseURL: "https://common-dev-34b09.firebaseio.com",
projectId: "common-dev-34b09",
storageBucket: "common-dev-34b09.appspot.com",
messagingSenderId: "870639147922",
appId: "1:870639147922:web:9ee954bb1dd52e25cb7f4b",
},
STAGE: {
apiKey: "AIzaSyBASCWJMV64mZJObeFEitLmdUC1HqmtjJk",
authDomain: "common-staging-1d426.firebaseapp.com",
databaseURL: "https://common-staging-1d426.firebaseio.com",
projectId: "common-staging-1d426",
storageBucket: "common-staging-1d426.appspot.com",
messagingSenderId: "701579202562",
appId: "1:701579202562:web:5729d8a875f98f6709571b",
},
PRODUCTION: {
apiKey: "AIzaSyAlYrKLd6KNKVkhmNEMKfb0cWHSWicCBOY",
authDomain: "common-production-67641.firebaseapp.com",
databaseURL: "https://common-production-67641.firebaseio.com",
projectId: "common-production-67641",
storageBucket: "common-production-67641.appspot.com",
messagingSenderId: "461029494046",
appId: "1:461029494046:web:4e2e4afbbeb7b487b48d0f",
},
};

let firebaseConfig = {};

switch (location.origin) {
case ENV.LOCAL:
case ENV.DEV: {
firebaseConfig = FIREBASE_CONFIG_ENV.DEV;
break;
}
case ENV.STAGE: {
firebaseConfig = FIREBASE_CONFIG_ENV.STAGE;
break;
}
case ENV.PRODUCTION: {
firebaseConfig = FIREBASE_CONFIG_ENV.PRODUCTION;
break;
}
default: {
firebaseConfig = FIREBASE_CONFIG_ENV.DEV;
break;
}
}

firebase.initializeApp(firebaseConfig);

const messaging = firebase.messaging();

messaging.onBackgroundMessage((payload) => {
const notificationTitle = payload.notification.title;
const notificationOptions = {
body: payload.notification.body,
data: payload.data,
icon: "/logo.png",
};

self.registration.showNotification(notificationTitle, notificationOptions);
});
Binary file added public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const local: Configuration = {
deadSeaCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
parentsForClimateCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
saadiaCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
vapidKey:
"BHVFyNetSC6oA2uFejnUFuDcSUYcas2R5lwW80z6gZc6zODp7rRdh2t8bht3LygJWjyI1toV165EYgdZqxCS_Y4",
};

const dev: Configuration = {
Expand All @@ -44,6 +46,8 @@ const dev: Configuration = {
deadSeaCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
parentsForClimateCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
saadiaCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
vapidKey:
"BHVFyNetSC6oA2uFejnUFuDcSUYcas2R5lwW80z6gZc6zODp7rRdh2t8bht3LygJWjyI1toV165EYgdZqxCS_Y4",
};

const stage: Configuration = {
Expand All @@ -62,6 +66,8 @@ const stage: Configuration = {
deadSeaCommonId: "a55a1e9b-104a-4866-9f4f-3e017bbae281",
parentsForClimateCommonId: "a55a1e9b-104a-4866-9f4f-3e017bbae281",
saadiaCommonId: "a55a1e9b-104a-4866-9f4f-3e017bbae281",
vapidKey:
"BBvr8z8QaPSJJfIRxmjBrq5Vs49BY95uZK_6QFyR7gKWgwrs5toDy-hvwWEtk-rbkVHBgOu9l2orK45u1n--9M0",
};

const production: Configuration = {
Expand All @@ -80,6 +86,8 @@ const production: Configuration = {
deadSeaCommonId: "6cfbfae6-2e5c-4b3b-ba70-e8fd871f48e2",
parentsForClimateCommonId: "04ac2ec2-5cb2-4ab9-ae3f-5f223f482768",
saadiaCommonId: "7c8c8996-b678-44df-9a57-e291431eb00f",
vapidKey:
"BKJ324iR-B5SoDG42bMrC_Q_poAv7BO-Z3AuMh5Grrg6TxO1QnN6mgzt2KyFFax0JSuuUhUKP-OrcTUPfboVqns",
};

const config: ConfigurationObject = {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ThemeHandler,
UserNotificationsAmountHandler,
WebViewLoginHandler,
NotificationsHandler,
} from "./handlers";
import { Router } from "./router";

Expand All @@ -34,6 +35,7 @@ const App = () => {
<ThemeHandler />
<UserNotificationsAmountHandler />
<WebViewLoginHandler />
<NotificationsHandler />
<LoginContainer />
<Router />
</ReactRouter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { FC, useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { selectUser } from "@/pages/Auth/store/selectors";
import { NotificationService } from "@/services";

const NotificationsHandler: FC = () => {
const user = useSelector(selectUser());
const userId = user?.uid;
const [isRegistered, setIsRegistered] = useState(false);

useEffect(() => {
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("/firebase-messaging-sw.js")
.then((registration) => {
setIsRegistered(true);
return registration;
})
.catch((err) => {
console.log("ServiceWorker registration failed: ", err);
});
}
}, []);

useEffect(() => {
if (!userId && !isRegistered) {
return;
}

let unsubscribeOnMessage;
(async () => {
const hasPermissions = await NotificationService.requestPermissions();
if (hasPermissions) {
await NotificationService.saveFCMToken();

unsubscribeOnMessage = NotificationService.onForegroundMessage();
}
})();

return () => {
unsubscribeOnMessage && unsubscribeOnMessage();
};
}, [userId, isRegistered]);

return null;
};

export default NotificationsHandler;
1 change: 1 addition & 0 deletions src/pages/App/handlers/NotificationsHandler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as NotificationsHandler } from "./NotificationsHandler";
1 change: 1 addition & 0 deletions src/pages/App/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./TextDirectionHandler";
export * from "./UserNotificationsAmountHandler";
export * from "./WebViewLoginHandler";
export * from "./ThemeHandler";
export * from "./NotificationsHandler";
3 changes: 2 additions & 1 deletion src/pages/OldCommon/hooks/useCommonMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const useCommonMember = (options: Options = {}): Return => {
loading: false,
fetched: true,
data: {
commonId,
...commonMember,
...generateCirclesDataForCommonMember(
governance.circles,
Expand Down Expand Up @@ -189,7 +190,7 @@ export const useCommonMember = (options: Options = {}): Return => {
}
}
},
[state, userId],
[state, userId, commonId],
);

const setCommonMember = useCallback(
Expand Down
6 changes: 3 additions & 3 deletions src/pages/OldCommon/hooks/useCommonMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const useCommonMembers = ({ commonId }: Options): Return => {

const user = cachedUserStates[commonMember.userId]?.data;

return user ? [...acc, { ...commonMember, user }] : acc;
return user ? [...acc, { ...commonMember, user, commonId }] : acc;
}, []);

return {
Expand Down Expand Up @@ -178,7 +178,7 @@ export const useCommonMembers = ({ commonId }: Options): Return => {
({ uid }) => uid === commonMember.userId,
);

return user ? [...acc, { ...commonMember, user }] : acc;
return user ? [...acc, { ...commonMember, user, commonId }] : acc;
}, []);

return {
Expand All @@ -198,7 +198,7 @@ export const useCommonMembers = ({ commonId }: Options): Return => {
}));
}
})();
}, [commonMembersState.data]);
}, [commonMembersState.data, commonId]);

return {
...state,
Expand Down
13 changes: 9 additions & 4 deletions src/pages/common/components/ChatComponent/ChatComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,15 @@ export default function ChatComponent({
chatChannelId: chatChannel?.id || "",
participants: chatChannel?.participants,
});
const users = chatChannel ? chatUsers : discussionUsers;
const discussionMessages = chatChannel
? chatMessagesData.data
: discussionMessagesData.data || [];
const users = useMemo(
() => (chatChannel ? chatUsers : discussionUsers),
[chatUsers, discussionUsers, chatChannel],
);
const discussionMessages = useMemo(
() =>
chatChannel ? chatMessagesData.data : discussionMessagesData.data || [],
[chatChannel, chatMessagesData.data, discussionMessagesData.data],
);
const isFetchedDiscussionMessages =
discussionMessagesData.fetched || chatMessagesData.fetched;
const areInitialMessagesLoading = isChatChannel
Expand Down
Loading
Loading