Skip to content

Commit

Permalink
Merge branch 'dev' into cw-2350-tabs-layout-click-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
roienatan committed Dec 4, 2023
2 parents 510f515 + 8a2ba99 commit 3f5669d
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { webviewLogin } from "@/pages/Auth/store/actions";
import { history } from "@/shared/appConfig";
import { WebviewActions } from "@/shared/constants";
import { FirebaseCredentials } from "@/shared/interfaces/FirebaseCredentials";
import { getInboxPagePath_v04 } from "@/shared/utils";
import { getInboxPagePath } from "@/shared/utils";
import { parseJson } from "@/shared/utils/json";

const WebViewLoginHandler: FC = () => {
Expand All @@ -25,7 +25,7 @@ const WebViewLoginHandler: FC = () => {
window.ReactNativeWebView.postMessage(
WebviewActions.loginSuccess,
);
history.push(getInboxPagePath_v04());
history.push(getInboxPagePath());
} else {
window.ReactNativeWebView.postMessage(WebviewActions.loginError);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC } from "react";
import React, { FC, useEffect } from "react";
import SplitPane from "react-split-pane";
import { useLockedBody } from "@/shared/hooks";
import styles from "./SplitView.module.scss";

interface SplitViewProps {
Expand All @@ -14,6 +15,14 @@ interface SplitViewProps {
const SplitView: FC<SplitViewProps> = (props) => {
const { className, size, minSize, maxSize, defaultSize, onChange, children } =
props;
const { lockBodyScroll, unlockBodyScroll } = useLockedBody();

useEffect(() => {
lockBodyScroll();
return () => {
unlockBodyScroll();
};
}, []);

return (
<SplitPane
Expand All @@ -35,7 +44,8 @@ const SplitView: FC<SplitViewProps> = (props) => {
flexDirection: "column",
}}
pane1Style={{
overflow: "hidden",
overflow: "scroll",
height: "100vh",
}}
>
{children}
Expand Down
47 changes: 33 additions & 14 deletions src/services/Common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { isEqual } from "lodash";
import { getCommonState } from "@/pages/OldCommon/store/actions";
import {
getCommonState,
updateCommonState,
} from "@/pages/OldCommon/store/actions";
import { commonMembersSubCollection } from "@/pages/OldCommon/store/api";
import { store } from "@/shared/appConfig";
import {
Expand Down Expand Up @@ -53,22 +56,38 @@ class CommonService {
public getCachedCommonById = async (
commonId: string,
): Promise<Common | null> => {
const commonState = store.getState().commons.commonStates[commonId];
try {
const commonState = store.getState().commons.commonStates[commonId];

if (commonState?.fetched) {
return commonState.data;
}
if (commonState?.loading) {
return await waitForCommonToBeLoaded(commonId);
}
if (commonState?.fetched) {
return commonState.data;
}
if (commonState?.loading) {
return await waitForCommonToBeLoaded(commonId);
}

store.dispatch(
getCommonState.request({
payload: { commonId },
}),
);
store.dispatch(
getCommonState.request({
payload: { commonId },
}),
);

return await waitForCommonToBeLoaded(commonId);
} catch (err) {
const common = await this.getCommonById(commonId, true);
store.dispatch(
updateCommonState({
commonId,
state: {
loading: false,
fetched: true,
data: common,
},
}),
);

return await waitForCommonToBeLoaded(commonId);
return common;
}
};

public getCommonsByIds = async (
Expand Down
43 changes: 33 additions & 10 deletions src/services/Discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import {
CreateDiscussionDto,
EditDiscussionDto,
} from "@/pages/OldCommon/interfaces";
import { ApiEndpoint } from "@/shared/constants";
import { ApiEndpoint, FirestoreDataSource } from "@/shared/constants";
import { UnsubscribeFunction } from "@/shared/interfaces";
import { Collection, Discussion } from "@/shared/models";
import {
convertObjectDatesToFirestoreTimestamps,
firestoreDataConverter,
transformFirebaseDataSingle,
} from "@/shared/utils";
import firebase from "@/shared/utils/firebase";
import firebase, { isFirestoreCacheError } from "@/shared/utils/firebase";
import Api from "./Api";

const converter = firestoreDataConverter<Discussion>();
Expand All @@ -24,15 +23,35 @@ class DiscussionService {

public getDiscussionById = async (
discussionId: string,
source = FirestoreDataSource.Default,
): Promise<Discussion | null> => {
const discussion = await this.getDiscussionCollection()
.doc(discussionId)
.get();
try {
const snapshot = await this.getDiscussionCollection()
.doc(discussionId)
.get({ source });
const fromCache = snapshot.metadata.fromCache ? "local cache" : "server";
const discussion = snapshot?.data() || null;

return (
(discussion && transformFirebaseDataSingle<Discussion>(discussion)) ||
null
);
console.log(
`getDiscussionById [${fromCache}]`,
discussionId,
snapshot?.data() || null,
);
if (!discussion && source === FirestoreDataSource.Cache) {
return this.getDiscussionById(discussionId, FirestoreDataSource.Server);
}

return discussion;
} catch (error) {
if (
source === FirestoreDataSource.Cache &&
isFirestoreCacheError(error)
) {
return this.getDiscussionById(discussionId, FirestoreDataSource.Server);
} else {
throw error;
}
}
};

public createDiscussion = async (
Expand Down Expand Up @@ -65,9 +84,13 @@ class DiscussionService {

return query.onSnapshot((snapshot) => {
const discussion = snapshot.data();
const source = snapshot.metadata.fromCache ? "local cache" : "server";

if (discussion) {
console.log(`discussion found! [${source}]`, discussionId);
callback(discussion);
} else {
console.log(`discussion was not found [${source}]`, discussionId);
}
});
};
Expand Down
9 changes: 8 additions & 1 deletion src/services/Proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ class ProposalService {
const query = this.getProposalCollection().doc(proposalId);

return query.onSnapshot((snapshot) => {
callback(transformFirebaseDataSingle<Proposal>(snapshot));
const proposal = snapshot.data();

if (proposal) {
console.log("proposal found!", proposalId);
callback(proposal);
} else {
console.log("proposal was not found", proposalId);
}
});
};

Expand Down
9 changes: 5 additions & 4 deletions src/shared/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React, {
import ReactDOM from "react-dom";
import classNames from "classnames";
import { v4 as uuidv4 } from "uuid";
import { useComponentWillUnmount } from "../../hooks";
import { useComponentWillUnmount, useLockedBody } from "../../hooks";
import Close2Icon from "../../icons/close2.icon";
import LeftArrowIcon from "../../icons/leftArrow.icon";
import { ModalProps, ModalRef, ModalType } from "../../interfaces";
Expand Down Expand Up @@ -54,6 +54,7 @@ const Modal: ForwardRefRenderFunction<ModalRef, ModalProps> = (
const { sticky: isFooterSticky = false } = footerOptions;
const [showClosePrompt, setShowClosePrompt] = useState(false);
const modalId = useMemo(() => `modal-${uuidv4()}`, []);
const { lockBodyScroll, unlockBodyScroll } = useLockedBody();

const handleModalContainerClick: MouseEventHandler = (event) => {
event.stopPropagation();
Expand Down Expand Up @@ -87,7 +88,7 @@ const Modal: ForwardRefRenderFunction<ModalRef, ModalProps> = (
}

const modalRoot = document.getElementById(modalId);
document.body.style.overflow = "initial";
unlockBodyScroll();

if (modalRoot) {
document.body.removeChild(modalRoot);
Expand All @@ -97,12 +98,12 @@ const Modal: ForwardRefRenderFunction<ModalRef, ModalProps> = (
useEffect(() => {
if (!isShowing) {
const modalRoot = document.getElementById(modalId);
document.body.style.overflow = "initial";
unlockBodyScroll();
if (modalRoot) {
document.body.removeChild(modalRoot);
}
} else {
document.body.style.overflow = "hidden";
lockBodyScroll();
}
}, [isShowing, modalId]);

Expand Down
5 changes: 5 additions & 0 deletions src/shared/constants/firestoreDataSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum FirestoreDataSource {
Default = "default",
Server = "server",
Cache = "cache",
}
1 change: 1 addition & 0 deletions src/shared/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from "./dynamicLink";
export * from "./endpoint";
export * from "./environment";
export * from "./errorCode";
export * from "./firestoreDataSource";
export * from "./followFeedItemAction";
export * from "./formErrorMessages";
export * from "./getChatChannelUserStatusKey";
Expand Down
9 changes: 6 additions & 3 deletions src/store/states/cache/saga/getDiscussionStateById.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { call, put, select } from "redux-saga/effects";
import { DiscussionService } from "@/services";
import { FirestoreDataSource } from "@/shared/constants";
import { Awaited, LoadingState } from "@/shared/interfaces";
import { Discussion } from "@/shared/models";
import { isError } from "@/shared/utils";
Expand Down Expand Up @@ -35,9 +36,11 @@ export function* getDiscussionStateById({
},
}),
);
const data = (yield call(requestFunction, discussionId)) as Awaited<
ReturnType<typeof requestFunction>
>;
const data = (yield call(
requestFunction,
discussionId,
FirestoreDataSource.Cache,
)) as Awaited<ReturnType<typeof requestFunction>>;

yield put(
updateStateAction({
Expand Down
14 changes: 13 additions & 1 deletion src/store/states/inbox/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ export const reducer = createReducer<InboxState, Action>(INITIAL_INBOX_STATE)
produce(state, (nextState) => {
const payload = action.payload.filter(
(item) =>
item.item.itemId !== state.sharedItem?.itemId &&
!nextState.chatChannelItems.some(
(chatChannelItem) => chatChannelItem.itemId === item.item.itemId,
),
Expand Down Expand Up @@ -558,7 +559,18 @@ export const reducer = createReducer<InboxState, Action>(INITIAL_INBOX_STATE)
)
.handleAction(actions.setSharedInboxItem, (state, { payload }) =>
produce(state, (nextState) => {
nextState.sharedItem = payload && { ...payload };
const sharedItem = payload && { ...payload };

nextState.sharedItem = sharedItem;

if (sharedItem && nextState.items.data) {
nextState.items = {
...nextState.items,
data: nextState.items.data.filter(
(item) => item.itemId !== sharedItem.itemId,
),
};
}
}),
)
.handleAction(actions.addChatChannelItem, (state, { payload }) =>
Expand Down
13 changes: 12 additions & 1 deletion src/store/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const clearNonFinishedStates = <T extends unknown>(
states: Record<string, LoadingState<T>>,
): Record<string, LoadingState<T>> =>
Object.entries(states).reduce((acc, [key, value]) => {
if (value.loading || !value.fetched) {
if (value.loading || !value.fetched || !value.data) {
return acc;
}

Expand Down Expand Up @@ -85,7 +85,18 @@ export const cacheTransform = createTransform(
(inboundState: CacheState) => ({
...INITIAL_CACHE_STATE,
userStates: clearNonFinishedStates(inboundState.userStates),
governanceByCommonIdStates: clearNonFinishedStates(
inboundState.governanceByCommonIdStates,
),
discussionStates: clearNonFinishedStates(inboundState.discussionStates),
proposalStates: clearNonFinishedStates(inboundState.proposalStates),
feedByCommonIdStates: inboundState.feedByCommonIdStates,
feedItemUserMetadataStates: clearNonFinishedStates(
inboundState.feedItemUserMetadataStates,
),
chatChannelUserStatusStates: clearNonFinishedStates(
inboundState.chatChannelUserStatusStates,
),
}),
(outboundState: CacheState) => outboundState,
{ whitelist: ["cache"] },
Expand Down

0 comments on commit 3f5669d

Please sign in to comment.