Skip to content

Commit a66d8a5

Browse files
authored
Merge pull request #2764 from daostack/dev
Instant reorder
2 parents a8aa483 + 0e335fd commit a66d8a5

File tree

39 files changed

+932
-330
lines changed

39 files changed

+932
-330
lines changed

src/pages/Auth/store/saga.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
subscribeToNotification,
77
} from "@/pages/OldCommon/store/api";
88
import { UserService } from "@/services";
9-
import { store } from "@/shared/appConfig";
9+
import { persistor, store } from "@/shared/appConfig";
1010
import { Awaited } from "@/shared/interfaces";
1111
import { FirebaseCredentials } from "@/shared/interfaces/FirebaseCredentials";
1212
import { EventTypeState, NotificationItem } from "@/shared/models/Notification";
@@ -48,6 +48,7 @@ import firebase from "../../../shared/utils/firebase";
4848
import { UserCreationDto } from "../interface";
4949
import * as actions from "./actions";
5050
import { createdUserApi, deleteUserApi, getUserData } from "./api";
51+
import { resetOptimisticState } from "@/store/states/optimistic/actions";
5152

5253
const getAuthProviderFromProviderData = (
5354
providerData?: firebase.User["providerData"],
@@ -533,15 +534,27 @@ function* confirmVerificationCodeSaga({
533534
}
534535

535536
function* logOut() {
537+
538+
yield put(resetOptimisticState());
539+
// Wait for persistor.purge() to complete
540+
yield call([persistor, persistor.purge]);
541+
yield call([persistor, persistor.flush]);
542+
543+
// Now clear localStorage
536544
localStorage.clear();
537-
firebase.auth().signOut();
538545

546+
// Sign out from Firebase
547+
yield call([firebase.auth(), firebase.auth().signOut]);
548+
549+
// Notify React Native WebView if applicable
539550
if (window.ReactNativeWebView) {
540-
window?.ReactNativeWebView?.postMessage(WebviewActions.logout);
551+
window.ReactNativeWebView.postMessage(WebviewActions.logout);
541552
}
542553

554+
// Reset global data and navigate to home
543555
resetGlobalData(true);
544556
history.push(ROUTE_PATHS.HOME);
557+
545558
yield true;
546559
}
547560

src/pages/OldCommon/components/CommonDetailContainer/WalletComponent/hooks.ts

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -25,116 +25,116 @@ export const useCommonTransactionsChartDataSet =
2525
orderedCommonTransactions: TransactionData[],
2626
commonCreatedAt?: Time,
2727
) => {
28-
const uniqueTransactionsMonths = new Set();
29-
30-
const groupedByMonthPayInsSummaries: { [key: string]: number } = {};
31-
const groupedByMonthPayOutsSummaries: { [key: string]: number } = {};
32-
33-
orderedCommonTransactions
34-
.filter(
35-
(transaction) =>
36-
getMonthsDifference(
37-
new Date(transaction.createdAt.seconds * 1000),
38-
new Date(),
39-
) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT,
40-
)
41-
.map((transaction) => ({
42-
...transaction,
43-
amount: transaction.amount / 100,
44-
}))
45-
.reverse()
46-
.map((transaction) => {
47-
const transactionMonthNotation =
48-
BRIEF_MONTH_NAMES[
49-
new Date(transaction.createdAt.seconds * 1000).getMonth()
50-
];
51-
52-
uniqueTransactionsMonths.add(transactionMonthNotation);
53-
54-
if (
55-
groupedByMonthPayInsSummaries[transactionMonthNotation] ===
56-
undefined
57-
)
58-
groupedByMonthPayInsSummaries[transactionMonthNotation] = 0;
59-
60-
if (
61-
groupedByMonthPayOutsSummaries[transactionMonthNotation] ===
62-
undefined
63-
)
64-
groupedByMonthPayOutsSummaries[transactionMonthNotation] = 0;
65-
66-
if (transaction.type === TransactionType.PayIn) {
67-
groupedByMonthPayInsSummaries[transactionMonthNotation] +=
68-
transaction.amount;
69-
} else if (transaction.type === TransactionType.PayOut) {
70-
groupedByMonthPayOutsSummaries[transactionMonthNotation] +=
71-
transaction.amount;
72-
}
73-
74-
return transaction;
75-
});
76-
77-
const chartMonthLabelsList = Array.from(
78-
uniqueTransactionsMonths,
79-
) as string[];
80-
81-
/*
82-
FIXME: tempo decision to prevent common's crashing (some common-records have createdAt set in null),
83-
should be reverted after full merging of the Governance & clearing the DB from legacy stuff
84-
*/
85-
if (commonCreatedAt) {
86-
const commonCreatedAtMonthNotation =
87-
BRIEF_MONTH_NAMES[
88-
new Date(commonCreatedAt.seconds * 1000).getMonth()
89-
];
90-
91-
if (
92-
!chartMonthLabelsList.includes(commonCreatedAtMonthNotation) &&
93-
getMonthsDifference(
94-
new Date(commonCreatedAt.seconds * 1000),
95-
new Date(),
96-
) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT
97-
) {
98-
chartMonthLabelsList.unshift(commonCreatedAtMonthNotation);
99-
100-
groupedByMonthPayInsSummaries[commonCreatedAtMonthNotation] = 0;
101-
groupedByMonthPayOutsSummaries[commonCreatedAtMonthNotation] = 0;
102-
}
103-
}
104-
105-
const payInsChartData = chartMonthLabelsList.map(
106-
(monthLabel) => groupedByMonthPayInsSummaries[monthLabel],
107-
);
108-
const payOutsChartData = chartMonthLabelsList.map(
109-
(monthLabel) => groupedByMonthPayOutsSummaries[monthLabel],
110-
);
111-
const balanceChartData = payInsChartData.reduce(
112-
(
113-
accum: { currentBalance: number; balances: number[] },
114-
payInsMonthSum,
115-
index,
116-
) => {
117-
let newBalance = accum.currentBalance;
118-
119-
newBalance += payInsMonthSum;
120-
newBalance -= payOutsChartData[index];
121-
122-
return {
123-
currentBalance: newBalance,
124-
balances: [...accum.balances, newBalance],
125-
};
126-
},
127-
{
128-
currentBalance: 0,
129-
balances: [],
130-
},
131-
).balances;
28+
// const uniqueTransactionsMonths = new Set();
29+
30+
// const groupedByMonthPayInsSummaries: { [key: string]: number } = {};
31+
// const groupedByMonthPayOutsSummaries: { [key: string]: number } = {};
32+
33+
// orderedCommonTransactions
34+
// .filter(
35+
// (transaction) =>
36+
// getMonthsDifference(
37+
// new Date(transaction.createdAt.seconds * 1000),
38+
// new Date(),
39+
// ) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT,
40+
// )
41+
// .map((transaction) => ({
42+
// ...transaction,
43+
// amount: transaction.amount / 100,
44+
// }))
45+
// .reverse()
46+
// .map((transaction) => {
47+
// const transactionMonthNotation =
48+
// BRIEF_MONTH_NAMES[
49+
// new Date(transaction.createdAt.seconds * 1000).getMonth()
50+
// ];
51+
52+
// uniqueTransactionsMonths.add(transactionMonthNotation);
53+
54+
// if (
55+
// groupedByMonthPayInsSummaries[transactionMonthNotation] ===
56+
// undefined
57+
// )
58+
// groupedByMonthPayInsSummaries[transactionMonthNotation] = 0;
59+
60+
// if (
61+
// groupedByMonthPayOutsSummaries[transactionMonthNotation] ===
62+
// undefined
63+
// )
64+
// groupedByMonthPayOutsSummaries[transactionMonthNotation] = 0;
65+
66+
// if (transaction.type === TransactionType.PayIn) {
67+
// groupedByMonthPayInsSummaries[transactionMonthNotation] +=
68+
// transaction.amount;
69+
// } else if (transaction.type === TransactionType.PayOut) {
70+
// groupedByMonthPayOutsSummaries[transactionMonthNotation] +=
71+
// transaction.amount;
72+
// }
73+
74+
// return transaction;
75+
// });
76+
77+
// const chartMonthLabelsList = Array.from(
78+
// uniqueTransactionsMonths,
79+
// ) as string[];
80+
81+
// /*
82+
// FIXME: tempo decision to prevent common's crashing (some common-records have createdAt set in null),
83+
// should be reverted after full merging of the Governance & clearing the DB from legacy stuff
84+
// */
85+
// if (commonCreatedAt) {
86+
// const commonCreatedAtMonthNotation =
87+
// BRIEF_MONTH_NAMES[
88+
// new Date(commonCreatedAt.seconds * 1000).getMonth()
89+
// ];
90+
91+
// if (
92+
// !chartMonthLabelsList.includes(commonCreatedAtMonthNotation) &&
93+
// getMonthsDifference(
94+
// new Date(commonCreatedAt.seconds * 1000),
95+
// new Date(),
96+
// ) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT
97+
// ) {
98+
// chartMonthLabelsList.unshift(commonCreatedAtMonthNotation);
99+
100+
// groupedByMonthPayInsSummaries[commonCreatedAtMonthNotation] = 0;
101+
// groupedByMonthPayOutsSummaries[commonCreatedAtMonthNotation] = 0;
102+
// }
103+
// }
104+
105+
// const payInsChartData = chartMonthLabelsList.map(
106+
// (monthLabel) => groupedByMonthPayInsSummaries[monthLabel],
107+
// );
108+
// const payOutsChartData = chartMonthLabelsList.map(
109+
// (monthLabel) => groupedByMonthPayOutsSummaries[monthLabel],
110+
// );
111+
// const balanceChartData = payInsChartData.reduce(
112+
// (
113+
// accum: { currentBalance: number; balances: number[] },
114+
// payInsMonthSum,
115+
// index,
116+
// ) => {
117+
// let newBalance = accum.currentBalance;
118+
119+
// newBalance += payInsMonthSum;
120+
// newBalance -= payOutsChartData[index];
121+
122+
// return {
123+
// currentBalance: newBalance,
124+
// balances: [...accum.balances, newBalance],
125+
// };
126+
// },
127+
// {
128+
// currentBalance: 0,
129+
// balances: [],
130+
// },
131+
// ).balances;
132132

133133
return {
134-
chartMonthLabelsList,
135-
payInsChartData,
136-
payOutsChartData,
137-
balanceChartData,
134+
chartMonthLabelsList: [],
135+
payInsChartData: [],
136+
payOutsChartData: [],
137+
balanceChartData: [],
138138
};
139139
},
140140
[],

src/pages/common/components/ChatComponent/ChatComponent.tsx

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ import {
6565
selectOptimisticFeedItems,
6666
commonActions,
6767
selectOptimisticDiscussionMessages,
68+
inboxActions,
69+
optimisticActions,
70+
selectInstantDiscussionMessagesOrder,
6871
} from "@/store/states";
6972
import { ChatContentContext, ChatContentData } from "../CommonContent/context";
7073
import {
@@ -85,8 +88,10 @@ import {
8588
} from "./utils";
8689
import styles from "./ChatComponent.module.scss";
8790
import { BaseTextEditorHandles } from "@/shared/ui-kit/TextEditor/BaseTextEditor";
91+
import { useFeedItemContext } from "../FeedItem";
8892

8993
const BASE_CHAT_INPUT_HEIGHT = 48;
94+
const BASE_ORDER_INTERVAL = 1000;
9095

9196
interface ChatComponentInterface {
9297
commonId: string;
@@ -254,6 +259,20 @@ export default function ChatComponent({
254259
parseStringToTextEditorValue(),
255260
);
256261

262+
const {
263+
setIsInputFocused
264+
} = useFeedItemContext();
265+
266+
useEffect(() => {
267+
const isEmpty = checkIsTextEditorValueEmpty(message);
268+
if(!isEmpty || message.length > 1) {
269+
setIsInputFocused?.(true);
270+
} else {
271+
setIsInputFocused?.(false);
272+
}
273+
274+
},[message, setIsInputFocused])
275+
257276
const emojiCount = useMemo(
258277
() => countTextEditorEmojiElements(message),
259278
[message],
@@ -275,6 +294,9 @@ export default function ChatComponent({
275294
const optimisticDiscussionMessages = useSelector(
276295
selectOptimisticDiscussionMessages,
277296
);
297+
const instantDiscussionMessagesOrder = useSelector(selectInstantDiscussionMessagesOrder);
298+
299+
const currentChatOrder = instantDiscussionMessagesOrder.get(discussionId)?.order || 1;
278300

279301
const isOptimisticChat = optimisticFeedItems.has(discussionId);
280302

@@ -295,7 +317,7 @@ export default function ChatComponent({
295317
});
296318

297319
dispatch(
298-
commonActions.clearOptimisticDiscussionMessages(
320+
optimisticActions.clearOptimisticDiscussionMessages(
299321
optimisticMessageDiscussionId,
300322
),
301323
);
@@ -414,8 +436,8 @@ export default function ChatComponent({
414436
setMessages([]);
415437
}
416438
},
417-
1500,
418-
[newMessages, discussionId, dispatch],
439+
1500 + BASE_ORDER_INTERVAL * currentChatOrder,
440+
[newMessages, discussionId, dispatch, currentChatOrder],
419441
);
420442

421443
/**
@@ -573,7 +595,7 @@ export default function ChatComponent({
573595
}
574596

575597
if (isOptimisticChat) {
576-
dispatch(commonActions.setOptimisticDiscussionMessages(payload));
598+
dispatch(optimisticActions.setOptimisticDiscussionMessages(payload));
577599
} else {
578600
setMessages((prev) => {
579601
if (isFilesMessageWithoutTextAndImages) {
@@ -582,6 +604,7 @@ export default function ChatComponent({
582604

583605
return [...prev, ...filePreviewPayload, payload];
584606
});
607+
dispatch(optimisticActions.setInstantDiscussionMessagesOrder({discussionId}));
585608
}
586609

587610
if (isChatChannel) {
@@ -606,6 +629,23 @@ export default function ChatComponent({
606629
if (currentFilesPreview) {
607630
dispatch(chatActions.clearFilesPreview());
608631
}
632+
633+
const payloadUpdateFeedItem = {
634+
feedItemId,
635+
lastMessage: {
636+
messageId: pendingMessageId,
637+
ownerId: userId as string,
638+
userName: getUserName(user),
639+
ownerType: DiscussionMessageOwnerType.User,
640+
content: JSON.stringify(message),
641+
}
642+
};
643+
644+
dispatch(commonActions.setFeedItemUpdatedAt(payloadUpdateFeedItem));
645+
dispatch(inboxActions.setInboxItemUpdatedAt(payloadUpdateFeedItem));
646+
document
647+
.getElementById("feedLayoutWrapper")
648+
?.scrollIntoView({ behavior: "smooth" });
609649
focusOnChat();
610650
}
611651
},
@@ -620,6 +660,7 @@ export default function ChatComponent({
620660
isChatChannel,
621661
linkPreviewData,
622662
isOptimisticChat,
663+
feedItemId,
623664
],
624665
);
625666

0 commit comments

Comments
 (0)