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

Merge to master #26

Merged
merged 8 commits into from
Mar 4, 2022
4 changes: 3 additions & 1 deletion packages/junto-utils/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { Ad4mClient } from "@perspect3vism/ad4m";
import { ApolloClient, ApolloLink, InMemoryCache } from "@apollo/client";
import { WebSocketLink } from "@apollo/client/link/ws";

const PORT = parseInt(window.location.search.slice(6))

const apolloClient = new ApolloClient({
link: new WebSocketLink({
uri: `ws://localhost:4000/graphql`,
uri: `ws://localhost:${PORT}/graphql`,
options: {
reconnect: true,
},
Expand Down
8 changes: 7 additions & 1 deletion packages/junto-utils/react/ChatContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type State = {
scrollPosition?: number;
hasNewMessage: boolean;
isMessageFromSelf: boolean;
showLoadMore: boolean;
};

type ContextProps = {
Expand All @@ -52,6 +53,7 @@ const initialState: ContextProps = {
scrollPosition: 0,
hasNewMessage: false,
isMessageFromSelf: false,
showLoadMore: true
},
methods: {
loadMore: () => null,
Expand Down Expand Up @@ -351,7 +353,10 @@ export function ChatProvider({ perspectiveUuid, children }: any) {
}));

const cachedMessages = await dexieMessages.getAll();
const oldMessages = { ...state.keyedMessages, ...cachedMessages };
const oldMessages = {
...state.keyedMessages,
...cachedMessages
};

const newMessages = await getMessages({
perspectiveUuid,
Expand All @@ -370,6 +375,7 @@ export function ChatProvider({ perspectiveUuid, children }: any) {

setState((oldState) => ({
...oldState,
showLoadMore: Object.values(newMessages).length === 35,
isFetchingMessages: false,
}));

Expand Down
2 changes: 2 additions & 0 deletions packages/mini-chat-view/src/components/MessageItem/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@
}

& .messageItemContent p:first-of-type {
user-select: text !important;
margin-top: 0;
}

& .messageItemContent p:last-of-type {
user-select: text !important;
margin-bottom: 0;
}

Expand Down
11 changes: 8 additions & 3 deletions packages/mini-chat-view/src/components/MessageList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function MessageList({ perspectiveUuid, mainRef }) {
const scroller = useRef();

const {
state: { messages, isFetchingMessages, scrollPosition, hasNewMessage, isMessageFromSelf },
state: { messages, isFetchingMessages, scrollPosition, hasNewMessage, isMessageFromSelf, showLoadMore },
methods: {
loadMore,
removeReaction,
Expand Down Expand Up @@ -160,7 +160,7 @@ export default function MessageList({ perspectiveUuid, mainRef }) {
<Virtuoso
components={{
Header: () => (
<j-box py="500">
showLoadMore ? (<j-box py="500">
<j-flex a="center" j="center">
{isFetchingMessages ? (
<j-flex a="center" gap="300">
Expand All @@ -173,7 +173,12 @@ export default function MessageList({ perspectiveUuid, mainRef }) {
</j-button>
)}
</j-flex>
</j-box>
</j-box>) : (
<j-box py="500">
<j-flex a="center" j="center">
<j-text>You have reached the end...</j-text>
</j-flex>
</j-box>)
),
}}
ref={scroller}
Expand Down
6 changes: 3 additions & 3 deletions packages/mini-chat-view/src/components/TipTap/Mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default (name: string) =>

inline: true,

selectable: false,
selectable: true,

atom: true,

Expand Down Expand Up @@ -99,7 +99,7 @@ export default (name: string) =>
parseHTML() {
return [
{
tag: "span[data-mention]",
tag: `span[data-mention="${name}"]`,
},
];
},
Expand All @@ -108,7 +108,7 @@ export default (name: string) =>
return [
"span",
mergeAttributes(
{ "data-mention": "" },
{ "data-mention": name },
this.options.HTMLAttributes,
HTMLAttributes
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class MentionList extends Component<MentionListProps, MentionList
return true;
}

if (event.key === "Enter") {
if (event.key === "Enter" || event.key === 'Tab') {
this.enterHandler();
return true;
}
Expand Down
15 changes: 13 additions & 2 deletions packages/mini-chat-view/src/components/TipTap/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useRef } from "preact/hooks";
import { useState, useRef, useContext } from "preact/hooks";
import { useEditor, EditorContent } from "@tiptap/react";
import BulletList from "@tiptap/extension-bullet-list";
import ListItem from "@tiptap/extension-list-item";
Expand All @@ -21,6 +21,7 @@ import emojiList from "node-emoji/lib/emoji";
import { useEffect } from "preact/hooks";

import styles from "./index.scss";
import UIContext from "../../context/UIContext";

export default function Tiptap({
value,
Expand All @@ -33,6 +34,10 @@ export default function Tiptap({

const emojiPicker = useRef();

const {
state: { currentReply },
} = useContext(UIContext);

// This is needed because React ugh.
const sendCB = useRef(onSend);
const membersCB = useRef(members);
Expand Down Expand Up @@ -164,11 +169,17 @@ export default function Tiptap({
);

useEffect(() => {
if (editor) {
if (editor && value.length === 0) {
editor.commands.setContent(value);
}
}, [value]);

useEffect(() => {
if (currentReply) {
editor.commands.focus();
}
}, [currentReply])

function onEmojiClick(event: CustomEvent) {
if (editor) {
const anchorPosition = editor.view.state.selection;
Expand Down