Skip to content

Commit

Permalink
Merge pull request #1359 from ecency/chat-ui
Browse files Browse the repository at this point in the history
Chat UI
  • Loading branch information
feruzm authored Dec 29, 2023
2 parents ee3b097 + 375c1ad commit 73ffbe8
Show file tree
Hide file tree
Showing 113 changed files with 5,087 additions and 228 deletions.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"start:prod": "NODE_ENV=production node build/server.js"
},
"dependencies": {
"@ecency/ns-query": "^1.0.0",
"@ecency/render-helper": "^2.2.29",
"@ecency/render-helper-amp": "^1.1.0",
"@emoji-mart/data": "^1.1.2",
Expand All @@ -24,6 +25,7 @@
"@hiveio/hivescript": "^1.2.7",
"@loadable/component": "^5.15.2",
"@loadable/server": "^5.15.2",
"@noble/secp256k1": "^1.7.1",
"@popperjs/core": "^2.11.8",
"@tanstack/react-query": "^4.29.7",
"@tanstack/react-query-devtools": "^4.29.7",
Expand All @@ -35,6 +37,7 @@
"connected-react-router": "^6.8.0",
"cookie-parser": "^1.4.5",
"currency-symbol-map": "^4.0.4",
"date-fns": "^2.30.0",
"debounce": "^1.2.1",
"diff-match-patch": "^1.0.5",
"emoji-mart": "^5.5.2",
Expand All @@ -55,6 +58,7 @@
"moment": "^2.29.4",
"node-cache": "^5.1.0",
"node-html-parser": "^5.3.3",
"nostr-relaypool": "^0.6.28",
"numeral": "^2.0.6",
"path-to-regexp": "^6.1.0",
"qrcode": "^1.5.1",
Expand Down Expand Up @@ -135,7 +139,7 @@
"@types/webpack-env": "^1.14.0",
"@types/webscopeio__react-textarea-autocomplete": "^4.7.2",
"autoprefixer": "^10.4.14",
"babel-preset-razzle": "^4.0.5",
"babel-preset-razzle": "^4.2.18",
"html-webpack-plugin": "4.5.2",
"husky": "^8.0.1",
"jest": "^26.0.0",
Expand All @@ -145,9 +149,9 @@
"postcss": "8.4.31",
"postcss-cli": "^10.1.0",
"prettier": "^2.7.1",
"razzle": "^4.0.5",
"razzle-dev-utils": "^4.0.5",
"razzle-plugin-scss": "^4.0.5",
"razzle": "^4.2.18",
"razzle-dev-utils": "^4.2.18",
"razzle-plugin-scss": "^4.2.18",
"razzle-plugin-typescript": "^3.0.0",
"react-test-renderer": "^16.13.1",
"tailwindcss": "^3.3.2",
Expand Down
19 changes: 18 additions & 1 deletion src/common/api/queries.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useQuery } from "@tanstack/react-query";
import { useQueries, useQuery } from "@tanstack/react-query";
import { QueryIdentifiers } from "../core";
import { getPoints, getPointTransactions } from "./private-api";
import { useMappedStore } from "../store/use-mapped-store";
import axios from "axios";
import { catchPostImage } from "@ecency/render-helper";
import { Entry } from "../store/entries/types";
import { getAccountFull } from "./hive";

const DEFAULT = {
points: "0.000",
Expand Down Expand Up @@ -88,3 +89,19 @@ export function useImageDownloader(
}
);
}

export function useGetAccountFullQuery(username?: string) {
return useQuery([QueryIdentifiers.GET_ACCOUNT_FULL, username], () => getAccountFull(username!), {
enabled: !!username
});
}

export function useGetAccountsFullQuery(usernames: string[]) {
return useQueries({
queries: usernames.map((username) => ({
queryKey: [QueryIdentifiers.GET_ACCOUNT_FULL, username],
queryFn: () => getAccountFull(username!),
enabled: !!username
}))
});
}
188 changes: 108 additions & 80 deletions src/common/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ import Announcement from "./components/announcement";
import FloatingFAQ from "./components/floating-faq";
import { useMappedStore } from "./store/use-mapped-store";
import { EntriesCacheManager } from "./core";

import { UserActivityRecorder } from "./components/user-activity-recorder";
import { useGlobalLoader } from "./util/use-global-loader";
import useMount from "react-use/lib/useMount";
import { ChatPopUp } from "./features/chats/components/chat-popup";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { ChatContextProvider } from "@ecency/ns-query";
import { useGetAccountFullQuery } from "./api/queries";

// Define lazy pages
const ProfileContainer = loadable(() => import("./pages/profile-functional"));
Expand All @@ -50,6 +53,9 @@ const AuthPage = (props: any) => <AuthContainer {...props} />;
const SubmitContainer = loadable(() => import("./pages/submit"));
const SubmitPage = (props: any) => <SubmitContainer {...props} />;

const ChatsContainer = loadable(() => import("./features/chats/screens/chats"));
const ChatsPage = (props: any) => <ChatsContainer {...props} />;

const OnboardContainer = loadable(() => import("./pages/onboard"));
const OnboardPage = (props: any) => <OnboardContainer {...props} />;

Expand Down Expand Up @@ -80,9 +86,11 @@ const PurchasePage = (props: any) => <PurchaseContainer {...props} />;
const DecksPage = loadable(() => import("./pages/decks"));

const App = (props: any) => {
const { global } = useMappedStore();
const { global, activeUser } = useMappedStore();
const { hide } = useGlobalLoader();

const { data: activeUserAccount } = useGetAccountFullQuery(activeUser?.username);

useMount(() => {
// Drop hiding from main queue to give React time to render
setTimeout(() => hide(), 1);
Expand All @@ -100,88 +108,108 @@ const App = (props: any) => {
return (
<EntriesCacheManager>
{/*Excluded from production*/}
{/*<ReactQueryDevtools initialIsOpen={false} />*/}
<ReactQueryDevtools initialIsOpen={false} />
<Tracker />
<UserActivityRecorder />
<Switch>
<Route exact={true} path={routes.HOME} component={EntryIndexContainer} />
<Route exact={true} strict={true} path={routes.FILTER} component={EntryIndexContainer} />
<Route exact={true} strict={true} path={routes.USER_FEED} component={EntryIndexContainer} />
<Route exact={true} strict={true} path={routes.PURCHASE} component={PurchasePage} />
<Route exact={true} strict={true} path={routes.USER} component={ProfilePage} />
<Route exact={true} strict={true} path={routes.USER_SECTION} component={ProfilePage} />
<Route exact={true} strict={true} path={routes.ENTRY} component={EntryPage} />
<Route exact={true} strict={true} path={routes.COMMUNITIES} component={CommunitiesPage} />
<Route
exact={true}
strict={true}
path={routes.COMMUNITIES_CREATE}
component={CommunityCreatePage}
/>
<Route
exact={true}
strict={true}
path={routes.COMMUNITIES_CREATE_HS}
component={CommunityCreateHSPage}
/>
<Route exact={true} strict={true} path={routes.COMMUNITY} component={CommunityPage} />
<Route
exact={true}
strict={true}
path={routes.FILTER_TAG}
component={EntryIndexContainer}
/>
<Route exact={true} strict={true} path={routes.DISCOVER} component={DiscoverPage} />
<Route exact={true} path={routes.SEARCH} component={SearchPageContainer} />
<Route exact={true} path={routes.SEARCH_MORE} component={SearchMorePageContainer} />
<Route exact={true} strict={true} path={routes.AUTH} component={AuthPage} />
<Route exact={true} strict={true} path={routes.SUBMIT} component={SubmitPage} />
<Route exact={true} strict={true} path={routes.MARKET} component={MarketPage} />
<Route exact={true} strict={true} path={routes.EDIT} component={SubmitPage} />
<Route exact={true} strict={true} path={routes.SIGN_UP} component={SignUpPage} />
<Route exact={true} strict={true} path={routes.ONBOARD} component={OnboardPage} />
<Route exact={true} strict={true} path={routes.EDIT_DRAFT} component={SubmitPage} />
<Route exact={true} strict={true} path={routes.WITNESSES} component={WitnessesPage} />
<Route
exact={true}
strict={true}
path={routes.PROPOSALS}
component={ProposalsIndexContainer}
/>
<Route
exact={true}
strict={true}
path={routes.PROPOSAL_DETAIL}
component={ProposalDetailContainer}
/>
<Route
exact={true}
strict={true}
path={`/me${routes.PROPOSAL_DETAIL}`}
component={ProposalDetailContainer}
/>
<Route exact={true} strict={true} path={routes.ABOUT} component={AboutPage} />
<Route exact={true} strict={true} path={routes.GUESTS} component={GuestPostPage} />
<Route exact={true} strict={true} path={routes.CONTRIBUTE} component={ContributePage} />
<Route exact={true} strict={true} path={routes.PRIVACY} component={PrivacyPage} />
<Route exact={true} strict={true} path={routes.WHITE_PAPER} component={WhitePaperPage} />
<Route exact={true} strict={true} path={routes.TOS} component={TosPage} />
<Route exact={true} strict={true} path={routes.FAQ} component={FaqPage} />
<Route exact={true} strict={true} path={routes.CONTRIBUTORS} component={ContributorsPage} />
<Route
exact={true}
strict={true}
path={routes.DECKS}
component={global.usePrivate ? DecksPage : NotFound}
/>
<Route component={NotFound} />
</Switch>

<Announcement activeUser={props.activeUser} />
<FloatingFAQ />
<div id="popper-container" />
<ChatContextProvider activeUsername={activeUser?.username} activeUserData={activeUserAccount}>
<Switch>
<Route exact={true} path={routes.HOME} component={EntryIndexContainer} />
<Route exact={true} strict={true} path={routes.FILTER} component={EntryIndexContainer} />
<Route
exact={true}
strict={true}
path={routes.USER_FEED}
component={EntryIndexContainer}
/>
<Route exact={true} strict={true} path={routes.PURCHASE} component={PurchasePage} />
<Route exact={true} strict={true} path={routes.USER} component={ProfilePage} />
<Route exact={true} strict={true} path={routes.USER_SECTION} component={ProfilePage} />
<Route exact={true} strict={true} path={routes.ENTRY} component={EntryPage} />
<Route exact={true} strict={true} path={routes.COMMUNITIES} component={CommunitiesPage} />
<Route
exact={true}
strict={true}
path={routes.COMMUNITIES_CREATE}
component={CommunityCreatePage}
/>
<Route
exact={true}
strict={true}
path={routes.COMMUNITIES_CREATE_HS}
component={CommunityCreateHSPage}
/>
<Route exact={true} strict={true} path={routes.COMMUNITY} component={CommunityPage} />
<Route
exact={true}
strict={true}
path={routes.FILTER_TAG}
component={EntryIndexContainer}
/>
<Route exact={true} strict={true} path={routes.DISCOVER} component={DiscoverPage} />
<Route exact={true} path={routes.SEARCH} component={SearchPageContainer} />
<Route exact={true} path={routes.SEARCH_MORE} component={SearchMorePageContainer} />
<Route exact={true} strict={true} path={routes.AUTH} component={AuthPage} />
<Route exact={true} strict={true} path={routes.SUBMIT} component={SubmitPage} />
<Route
exact={true}
strict={true}
path={routes.CHATS}
component={global.usePrivate ? ChatsPage : NotFound}
/>
<Route exact={true} strict={true} path={routes.MARKET} component={MarketPage} />
<Route exact={true} strict={true} path={routes.EDIT} component={SubmitPage} />
<Route exact={true} strict={true} path={routes.SIGN_UP} component={SignUpPage} />
<Route exact={true} strict={true} path={routes.ONBOARD} component={OnboardPage} />
<Route exact={true} strict={true} path={routes.EDIT_DRAFT} component={SubmitPage} />
<Route exact={true} strict={true} path={routes.WITNESSES} component={WitnessesPage} />
<Route
exact={true}
strict={true}
path={routes.PROPOSALS}
component={ProposalsIndexContainer}
/>
<Route
exact={true}
strict={true}
path={routes.PROPOSAL_DETAIL}
component={ProposalDetailContainer}
/>
<Route
exact={true}
strict={true}
path={`/me${routes.PROPOSAL_DETAIL}`}
component={ProposalDetailContainer}
/>
<Route exact={true} strict={true} path={routes.ABOUT} component={AboutPage} />
<Route exact={true} strict={true} path={routes.GUESTS} component={GuestPostPage} />
<Route exact={true} strict={true} path={routes.CONTRIBUTE} component={ContributePage} />
<Route exact={true} strict={true} path={routes.PRIVACY} component={PrivacyPage} />
<Route exact={true} strict={true} path={routes.WHITE_PAPER} component={WhitePaperPage} />
<Route exact={true} strict={true} path={routes.TOS} component={TosPage} />
<Route exact={true} strict={true} path={routes.FAQ} component={FaqPage} />
<Route
exact={true}
strict={true}
path={routes.CONTRIBUTORS}
component={ContributorsPage}
/>
<Route
exact={true}
strict={true}
path={routes.DECKS}
component={global.usePrivate ? DecksPage : NotFound}
/>
<Route component={NotFound} />
</Switch>

<Announcement activeUser={props.activeUser} />
<FloatingFAQ />

<ChatPopUp {...props} />
</ChatContextProvider>
<div id="modal-overlay-container" />
<div id="modal-dialog-container" />
<div id="popper-container" />
</EntriesCacheManager>
);
};
Expand Down
14 changes: 8 additions & 6 deletions src/common/components/comment/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ exports[`(1) Default render 1`] = `
title="Emoji"
>
<svg
fill="currentColor"
viewBox="0 0 24 24"
>
<path
d="M20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12M22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2A10,10 0 0,1 22,12M10,9.5C10,10.3 9.3,11 8.5,11C7.7,11 7,10.3 7,9.5C7,8.7 7.7,8 8.5,8C9.3,8 10,8.7 10,9.5M17,9.5C17,10.3 16.3,11 15.5,11C14.7,11 14,10.3 14,9.5C14,8.7 14.7,8 15.5,8C16.3,8 17,8.7 17,9.5M12,17.23C10.25,17.23 8.71,16.5 7.81,15.42L9.23,14C9.68,14.72 10.75,15.23 12,15.23C13.25,15.23 14.32,14.72 14.77,14L16.19,15.42C15.29,16.5 13.75,17.23 12,17.23Z"
fill="currentColor"
/>
</svg>
</div>
Expand All @@ -227,9 +227,10 @@ exports[`(1) Default render 1`] = `
>
<svg
fill="currentColor"
height="16"
height="18"
strokeWidth="2"
viewBox="0 0 16 16"
width="16"
width="18"
xmlns="http://www.w3.org/2000/svg"
>
<path
Expand Down Expand Up @@ -556,11 +557,11 @@ exports[`(2) Cancellable, in progress 1`] = `
title="Emoji"
>
<svg
fill="currentColor"
viewBox="0 0 24 24"
>
<path
d="M20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12M22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2A10,10 0 0,1 22,12M10,9.5C10,10.3 9.3,11 8.5,11C7.7,11 7,10.3 7,9.5C7,8.7 7.7,8 8.5,8C9.3,8 10,8.7 10,9.5M17,9.5C17,10.3 16.3,11 15.5,11C14.7,11 14,10.3 14,9.5C14,8.7 14.7,8 15.5,8C16.3,8 17,8.7 17,9.5M12,17.23C10.25,17.23 8.71,16.5 7.81,15.42L9.23,14C9.68,14.72 10.75,15.23 12,15.23C13.25,15.23 14.32,14.72 14.77,14L16.19,15.42C15.29,16.5 13.75,17.23 12,17.23Z"
fill="currentColor"
/>
</svg>
</div>
Expand All @@ -575,9 +576,10 @@ exports[`(2) Cancellable, in progress 1`] = `
>
<svg
fill="currentColor"
height="16"
height="18"
strokeWidth="2"
viewBox="0 0 16 16"
width="16"
width="18"
xmlns="http://www.w3.org/2000/svg"
>
<path
Expand Down
Loading

0 comments on commit 73ffbe8

Please sign in to comment.