-
-
+
-
-
-
- -
-
-
12:15
-
- Lorem ipsum dolor sit amet, consectetur adipisicing elit.
-
-
- -
-
-
19:48
-
- Assumenda delectus deleniti dolores doloribus ducimus, et expedita facere iste laborum,
- nihil similique suscipit, ut voluptatem. Accusantium consequuntur doloremque ex molestiae
- nemo.
-
-
-
+
@@ -64,59 +145,50 @@ export const InboxView = () => {
-
-
-
- Круто, беру в оборот!
-
-
+
+
+
+
+
+ {(comment: { body: string; id: string; email: string }) => (
+
+
+ {comment.body}
+
+
+ {comment.email} id: {comment.id}
+
+
+
-
-
-
+ )}
+
-
-
- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut beatae earum iste itaque
- libero perspiciatis possimus quod! Accusamus, aliquam amet consequuntur debitis dolorum
- esse laudantium magni omnis rerum voluptatem voluptates!
-
-
- Отредактировано
-
-
-
-
-
-
-
-
-
-
-
- Нужна грамотная инфраструктура для сообщений, если ожидается нагрузка - надо опираться на
- это. Но в целом это несложно сделать.
-
-
-
-
-
-
+ {/*
*/}
+ {/* */}
+ {/*
*/}
-
diff --git a/src/graphql/query/im-chats.ts b/src/graphql/query/im-chats.ts
new file mode 100644
index 00000000..1fb48553
--- /dev/null
+++ b/src/graphql/query/im-chats.ts
@@ -0,0 +1,26 @@
+import { gql } from '@urql/core'
+
+export default gql`
+ query GetChatsQuery {
+ myChats {
+ error
+ chats {
+ title
+ description
+ updatedAt
+ messages {
+ id
+ author
+ body
+ replyTo
+ createdAt
+ }
+ users {
+ slug
+ name
+ userpic
+ }
+ }
+ }
+ }
+`
diff --git a/src/graphql/query/im-load-messages.ts b/src/graphql/query/im-load-messages.ts
new file mode 100644
index 00000000..ec3b83bf
--- /dev/null
+++ b/src/graphql/query/im-load-messages.ts
@@ -0,0 +1,16 @@
+import { gql } from '@urql/core'
+
+export default gql`
+ query LoadMessagesQuery($chatId: String!, $offset: Int, $amount: Int) {
+ loadChat(chatId: $chatId, offset: $offset, amount: $amount) {
+ error
+ messages {
+ author
+ body
+ createdAt
+ updatedAt
+ seen
+ }
+ }
+ }
+`
diff --git a/src/graphql/query/my-chats.ts b/src/graphql/query/my-chats.ts
deleted file mode 100644
index 043eab0b..00000000
--- a/src/graphql/query/my-chats.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { gql } from '@urql/core'
-
-export default gql`
- query GetChatsQuery {
- myChats {
- messages {
- chatId
- id
- author
- body
- replyTo
- createdAt
- }
- users {
- slug
- name
- pic
- }
- title
- createdAt
- }
- }
-`
diff --git a/src/pages/inbox.astro b/src/pages/inbox.astro
index eeb95b82..1c89eb69 100644
--- a/src/pages/inbox.astro
+++ b/src/pages/inbox.astro
@@ -4,7 +4,7 @@ import { Root } from '../components/Root'
import { apiClient } from '../utils/apiClient'
import { initRouter } from '../stores/router'
-const chatrooms = await apiClient.getInboxes()
+const chatrooms = await apiClient.getChats()
const { pathname, search } = Astro.url
initRouter(pathname, search)
diff --git a/src/stores/auth.ts b/src/stores/auth.ts
index 9662ebe8..5b07ad25 100644
--- a/src/stores/auth.ts
+++ b/src/stores/auth.ts
@@ -11,11 +11,15 @@ export const signIn = async (params) => {
setToken(authResult.token)
console.debug('signed in')
}
-export const signOut = () => {
- // TODO: call backend to revoke token
- setSession(null)
- resetToken()
- console.debug('signed out')
+export const signOut = async () => {
+ const result = await apiClient.authSignOut()
+ if (result.error) {
+ console.error('[auth] sign out error', result.error)
+ } else {
+ setSession(null)
+ resetToken()
+ console.debug('signed out')
+ }
}
export const [emailChecks, setEmailChecks] = createSignal<{ [email: string]: boolean }>({})
diff --git a/src/styles/Inbox.scss b/src/styles/Inbox.scss
index 2cda3771..fab4cbfb 100644
--- a/src/styles/Inbox.scss
+++ b/src/styles/Inbox.scss
@@ -1,16 +1,23 @@
main {
display: flex;
- height: 100%;
+ height: 100vh;
flex-direction: column;
position: relative;
}
.messages {
+ top: 74px;
+ height: calc(100% - 74px);
+ left: 0;
+ right: 0;
+ padding-left: 42px;
+ padding-right: 26px;
+ background: #fff;
display: flex;
flex: 1;
flex-direction: column;
- height: 100%;
- position: relative;
+ position: fixed;
+ z-index: 1;
> .row {
flex: 1;
@@ -23,34 +30,53 @@ main {
.author {
position: relative;
}
-
- .user--online .author {
- &::before {
- background: #2bb452;
- border: 5px solid #fff;
- border-radius: 100%;
- content: '';
- height: 5px;
- left: 20px;
- position: absolute;
- top: 0;
- width: 5px;
- z-index: 1;
- }
- }
-
- .circlewrap {
- position: absolute;
- }
}
-
+// список диалогов и юзеров
.chat-list {
- border-right: 1px solid #141414;
display: flex;
flex-direction: column;
+ padding: 10px;
+ height: calc(100% - 10px);
- .author__name {
- @include font-size(1.5rem);
+ $fade-height: 10px;
+ .holder {
+ overflow: hidden;
+ flex: 1;
+ position: relative;
+ padding: $fade-height 0;
+
+ &::before,
+ &::after {
+ content: '';
+ position: absolute;
+ width: 100%;
+ right: 10px;
+ z-index: 1;
+ height: $fade-height;
+ }
+
+ &::before {
+ top: 0;
+ background: linear-gradient(white, transparent $fade-height);
+ }
+ &::after {
+ bottom: 0;
+ background: linear-gradient(transparent, white $fade-height);
+ }
+
+ .dialogs {
+ scroll-behavior: smooth;
+ display: flex;
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ height: 100%;
+ overflow: auto;
+ flex-direction: column;
+ box-sizing: border-box;
+ }
}
}
@@ -60,41 +86,10 @@ main {
padding: 1em 0;
}
-.chat-list__search {
- display: flex;
-
- input,
- .button {
- border-radius: 2px;
- height: 5.6rem;
- line-height: 5.6rem;
- vertical-align: bottom;
- }
-
- input {
- border: 2px solid #e8e8e8;
- flex: 1;
- @include font-size(1.7rem);
-
- margin-right: 1.6rem;
- padding: 1.6rem 1.2rem;
- }
-
- .button {
- @include font-size(4rem);
-
- font-weight: 100;
- padding: 0;
- width: 5.6rem;
- }
-}
-
+// табы выбора списка
.chat-list__types {
@include font-size(1.7rem);
-
- margin-bottom: 1.5em;
- padding-top: 1em;
-
+ margin: 16px 0;
ul {
display: flex;
flex-wrap: wrap;
@@ -113,66 +108,6 @@ main {
}
}
-.chat-list__users {
- flex: 1;
- position: relative;
-
- ul {
- height: 100%;
- list-style: none;
- margin: 0;
- overflow: auto;
- padding: 0;
- position: absolute;
- width: 100%;
- }
-
- li {
- align-items: baseline;
- background: #fff;
- cursor: pointer;
- display: flex;
- flex-wrap: wrap;
- @include font-size(1.5rem);
-
- padding: 2.4rem 0.8rem;
- position: relative;
- transition: background-color 0.3s;
-
- &:hover {
- background: #f6f6f6;
- }
- }
-
- .chat-list__user--current {
- background: #f6f6f6;
- cursor: default;
- }
-
- .author {
- flex: 1;
- margin-bottom: 0;
- }
-
- .author__details {
- margin-left: 4.2rem;
- }
-
- .last-message-date {
- color: rgb(0 0 0 / 30%);
- @include font-size(1rem);
- }
-
- .last-message-text {
- color: rgb(0 0 0 / 30%);
- flex: 1 100%;
- margin-left: 4.2rem;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
-}
-
.interlocutor {
height: 56px;
box-sizing: content-box;
@@ -218,7 +153,6 @@ main {
.conversation__messages {
flex: 1;
- min-height: 20em;
overflow: auto;
position: relative;
}
@@ -226,14 +160,19 @@ main {
.conversation__message-form {
border-top: 1px solid #141414;
display: flex;
+ flex-direction: row;
+ align-items: center;
padding: 1em 1em 1em 0;
- input {
- border: none;
+ textarea {
@include font-size(2rem);
- height: 5.6rem;
+ font-family: inherit;
+ height: 4.4em;
width: 100%;
+ padding: 1em;
+ margin-bottom: 0;
+ min-height: unset;
}
button {
@@ -266,6 +205,7 @@ main {
position: absolute;
top: 0;
width: 100%;
+ scroll-behavior: smooth;
}
.conversation__date {
@@ -298,10 +238,11 @@ main {
}
.conversation__message {
- @include font-size(1.5rem);
+ font-size: 14px;
max-width: 60%;
- padding: 1.6rem 2.4rem;
+ border-radius: 16px;
+ padding: 12px 16px;
position: relative;
&:hover {
diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts
index a062cf9b..37aed542 100644
--- a/src/utils/apiClient.ts
+++ b/src/utils/apiClient.ts
@@ -28,7 +28,8 @@ import reactionUpdate from '../graphql/mutation/reaction-update'
import authorsBySlugs from '../graphql/query/authors-by-slugs'
import incrementView from '../graphql/mutation/increment-view'
import createArticle from '../graphql/mutation/article-create'
-import myChats from '../graphql/query/my-chats'
+import myChats from '../graphql/query/im-chats'
+import loadChat from '../graphql/query/im-load-messages'
import getRecentByLayout from '../graphql/query/layout-recent'
import getTopByLayout from '../graphql/query/layout-top'
import getTopMonthByLayout from '../graphql/query/layout-top-month'
@@ -337,7 +338,7 @@ export const apiClient = {
incrementView: async ({ articleSlug }) => {
await privateGraphQLClient.mutation(incrementView, { shout: articleSlug })
},
- getInboxes: async (payload = {}) => {
+ getChats: async (payload = {}) => {
const resp = await privateGraphQLClient.query(myChats, payload).toPromise()
return resp.data.myChats
},
@@ -354,5 +355,17 @@ export const apiClient = {
.query(getTopMonthByLayout, { amount, offset, layout })
.toPromise()
return resp.data.topMonthLayoutShouts
+ },
+ getChatMessages: async ({
+ chatId,
+ offset = 0,
+ amount = 50
+ }: {
+ chatId: string
+ offset?: number
+ amount?: number
+ }) => {
+ const resp = await privateGraphQLClient.query(loadChat, { chatId, offset, amount }).toPromise()
+ return resp.data.loadChat
}
}