Skip to content

Commit

Permalink
Merge pull request #1550 from ecency/feature/chats
Browse files Browse the repository at this point in the history
Feature/chats
  • Loading branch information
feruzm authored Feb 13, 2024
2 parents 5776eb6 + 84b31e3 commit a5c9048
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/common/components/comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ interface Props {
updateActiveUser: (data?: Account) => void;
deleteUser: (username: string) => void;
toggleUIProp: (what: ToggleType) => void;
onSubmit: (text: string) => void;
onSubmit: (text: string) => Promise<any>;
resetSelection?: () => void;
onCancel?: () => void;
inputRef?: Ref<any>;
Expand Down Expand Up @@ -154,10 +154,11 @@ export class Comment extends Component<Props, State> {
}, 50);
};

submit = () => {
submit = async () => {
const { text } = this.state;
const { onSubmit } = this.props;
onSubmit(text);
await onSubmit(text);
this.setState({ text: "" });
};

cancel = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/components/entry-index-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export class EntryIndexMenu extends Component<Props, States> {
) : null}
</ul>
</div>
<div className="kebab-icon">
<div className="kebab-icon flex">
<DropDown {...kebabMenuConfig} float="left" />
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/common/components/market-swap-form/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
}

@keyframes rotate {
to { transform: rotate(-360deg); }
to {
transform: rotate(-360deg);
}
}

.swap-button {
Expand All @@ -86,6 +88,11 @@
position: relative;
color: $primary;

> div, > div > svg {
width: auto !important;
height: auto !important;
}

&:hover, &:active, &:focus {
color: darken($primary, 5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function ChatsChannelMessages({ publicMessages, currentChannel, isPage }:
publicMessages?.length - 1 === i
? document
.querySelector(`[data-message-id="${message.id}"]`)
?.scrollIntoView()
?.scrollIntoView({ block: "nearest" })
: {},
100
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function ChatsMessagesView({ currentContact, currentChannel }: Pr
<>
<div
className={classNameObject({
"h-[100vh] md:h-full overflow-y-auto md:overflow-y-static": true
"h-[100vh] md:h-full overflow-y-auto md:overflow-y-visible": true
})}
ref={messagesBoxRef}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function ChatsDirectMessages(props: Props) {
groupedDirectMessages?.length - 1 === i && messages.length - 1 === j
? document
.querySelector(`[data-message-id="${message.id}"]`)
?.scrollIntoView()
?.scrollIntoView({ block: "nearest" })
: {},
300
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function ChatsSideBar(props: Props) {
</div>
)}
{directContacts?.map((contact) => (
<ChatSidebarDirectContact key={contact.pubkey} contact={contact} />
<ChatSidebarDirectContact isLink={true} key={contact.pubkey} contact={contact} />
))}
</>
)}
Expand Down
1 change: 1 addition & 0 deletions src/common/features/chats/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./use-create-temporary-contact";
export * from "./use-create-temporary-contact-from-param";
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useContext, useMemo } from "react";
import { useQueryClient } from "@tanstack/react-query";
import {
ChatContext,
ChatQueries,
DirectContact,
useDirectContactsQuery,
useGetPublicKeysQuery
} from "@ecency/ns-query";
import useDebounce from "react-use/lib/useDebounce";
import { useLocation } from "react-router";

export function useCreateTemporaryContactFromParam() {
const queryClient = useQueryClient();
const { setReceiverPubKey, activeUsername } = useContext(ChatContext);
const { search } = useLocation();
const usernameParam = useMemo(() => new URLSearchParams(search).get("username") ?? "", [search]);

const { isFetched: isContactsFetched } = useDirectContactsQuery();
const { data: contactKeys, isFetched, isError } = useGetPublicKeysQuery(usernameParam);

// Create temporary contact and select it when searching users
// `not_joined_${selectedAccount}` – special constructor for creating a temporary contact
return useDebounce(
() => {
if (usernameParam && isContactsFetched && (isFetched || isError)) {
const pubkey = contactKeys?.pubkey ?? `not_joined_${usernameParam}`;
queryClient.setQueryData<DirectContact[]>(
[ChatQueries.DIRECT_CONTACTS, activeUsername],
(data) => [
...(
queryClient.getQueryData<DirectContact[]>([
ChatQueries.DIRECT_CONTACTS,
activeUsername
]) ?? []
).filter((dc) => dc.pubkey !== pubkey),
{
name: usernameParam,
pubkey
}
]
);
setReceiverPubKey(pubkey);
}
},
1000,
[usernameParam, isContactsFetched, contactKeys, isFetched, isError]
);
}
6 changes: 4 additions & 2 deletions src/common/features/chats/screens/chats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
useKeysQuery
} from "@ecency/ns-query";
import { useUnmount } from "react-use";
import { useCreateTemporaryContactFromParam } from "../hooks";

interface Props extends PageProps {
match: match<{
Expand All @@ -41,6 +42,7 @@ export const Chats = ({ match, history }: Props) => {
const { receiverPubKey, revealPrivateKey, setReceiverPubKey } = useContext(ChatContext);
const { data: community } = useCommunityCache(match.params.username);

useCreateTemporaryContactFromParam();
const { publicKey, privateKey } = useKeysQuery();
const { data: directContacts } = useDirectContactsQuery();
const { data: channels } = useChannelsQuery();
Expand Down Expand Up @@ -117,13 +119,13 @@ export const Chats = ({ match, history }: Props) => {
}, []);

return isMounted() ? (
<div className="bg-blue-duck-egg dark:bg-transparent pt-[63px] min-h-full-dynamic">
<div className="bg-blue-duck-egg dark:bg-transparent pt-[63px] md:pt-[69px] h-full-dynamic">
<Feedback activeUser={activeUser} />
<NavBar history={history} />
<Meta title={title || _t("chat.page-title")} />

<div className="container mx-auto md:py-6">
<div className="grid grid-cols-12 overflow-hidden md:rounded-2xl bg-white md:border border-[--border-color] relative min-h-full-dynamic md:h-auto">
<div className="grid grid-cols-12 overflow-hidden md:rounded-2xl bg-white md:border border-[--border-color] relative h-full-dynamic md:min-h-full md:max-h-full">
<div className="col-span-12 md:col-span-4 xl:col-span-3 md:border-r border-[--border-color] md:h-[calc(100vh-69px-3rem)] overflow-y-auto">
{isReady ? (
<ChatsSideBar
Expand Down
16 changes: 13 additions & 3 deletions src/style/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
@layer utilities {
.w-full-dynamic {
width: 100vw;
width: 100dvw;
@media screen and (max-width: 768px) {
width: 100vw;
width: 100dvw;
}
}

.min-h-full-dynamic {
.h-full-dynamic {
min-height: 100vh;
min-height: 100dvh;
max-height: 100vh;

@media screen and (max-width: 768px) {
min-height: 100vh;
max-height: 100vh;
max-height: 100dvh;
min-height: 100dvh;
}
}
}

Expand Down

0 comments on commit a5c9048

Please sign in to comment.