From 7318f3365a4ccbb716127453de314e0ef8b10dca Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Thu, 14 Apr 2022 22:55:56 +0600 Subject: [PATCH] Threads special (#1399) * Draft Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> * Threads special Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- models/chunter/src/index.ts | 9 + models/chunter/src/plugin.ts | 1 + packages/presentation/src/utils.ts | 4 +- packages/query/src/__tests__/query.test.ts | 26 +- packages/query/src/index.ts | 2 +- packages/theme/styles/_layouts.scss | 1 + plugins/chunter-assets/assets/icons.svg | 3 + plugins/chunter-assets/lang/en.json | 5 +- plugins/chunter-assets/lang/ru.json | 5 +- plugins/chunter-assets/src/index.ts | 1 + .../src/components/Channel.svelte | 9 +- .../src/components/ChannelPresenter.svelte | 41 +-- .../src/components/ChannelSeparator.svelte | 6 +- .../src/components/Message.svelte | 68 +++-- .../src/components/Replies.svelte | 15 +- .../src/components/Thread.svelte | 199 ++++++++++++++ .../src/components/ThreadComment.svelte | 257 ------------------ .../src/components/ThreadView.svelte | 19 +- .../src/components/Threads.svelte | 55 ++++ .../src/components/icons/Bookmark.svelte | 2 +- .../src/components/icons/Emoji.svelte | 2 +- plugins/chunter-resources/src/index.ts | 35 ++- plugins/chunter-resources/src/plugin.ts | 7 +- plugins/chunter/src/index.ts | 1 + 24 files changed, 387 insertions(+), 386 deletions(-) create mode 100644 plugins/chunter-resources/src/components/Thread.svelte delete mode 100644 plugins/chunter-resources/src/components/ThreadComment.svelte create mode 100644 plugins/chunter-resources/src/components/Threads.svelte diff --git a/models/chunter/src/index.ts b/models/chunter/src/index.ts index ee7511180e..6f20bb38c2 100644 --- a/models/chunter/src/index.ts +++ b/models/chunter/src/index.ts @@ -168,6 +168,15 @@ export function createModel (builder: Builder): void { icon: chunter.icon.Chunter, hidden: false, navigatorModel: { + specials: [ + { + id: 'threads', + label: chunter.string.Threads, + icon: chunter.icon.Thread, + component: chunter.component.Threads, + position: 'top' + } + ], spaces: [ { label: chunter.string.Channels, diff --git a/models/chunter/src/plugin.ts b/models/chunter/src/plugin.ts index 21190c167f..87c05de9e3 100644 --- a/models/chunter/src/plugin.ts +++ b/models/chunter/src/plugin.ts @@ -26,6 +26,7 @@ export default mergeIds(chunterId, chunter, { component: { CommentPresenter: '' as AnyComponent, ChannelPresenter: '' as AnyComponent, + Threads: '' as AnyComponent, ThreadView: '' as AnyComponent }, action: { diff --git a/packages/presentation/src/utils.ts b/packages/presentation/src/utils.ts index 0c43df9336..f099b992b1 100644 --- a/packages/presentation/src/utils.ts +++ b/packages/presentation/src/utils.ts @@ -16,7 +16,7 @@ import core, { AnyAttribute, ArrOf, AttachedDoc, Class, Client, Collection, Doc, DocumentQuery, - FindOptions, getCurrentAccount, Ref, RefTo, Tx, TxOperations, TxResult + FindOptions, FindResult, getCurrentAccount, Ref, RefTo, Tx, TxOperations, TxResult } from '@anticrm/core' import login from '@anticrm/login' import { getMetadata } from '@anticrm/platform' @@ -62,7 +62,7 @@ export class LiveQuery { query( _class: Ref>, query: DocumentQuery, - callback: (result: T[]) => void, + callback: (result: FindResult) => void, options?: FindOptions ): void { this.unsubscribe() diff --git a/packages/query/src/__tests__/query.test.ts b/packages/query/src/__tests__/query.test.ts index 33a42bc9ab..f85616fe95 100644 --- a/packages/query/src/__tests__/query.test.ts +++ b/packages/query/src/__tests__/query.test.ts @@ -386,10 +386,10 @@ describe('query', () => { const comment = result[0] if (comment !== undefined) { if (attempt > 0) { - expect((comment as WithLookup).$lookup?.space?._id).toEqual(futureSpace._id) + expect(comment.$lookup?.space?._id).toEqual(futureSpace._id) resolve(null) } else { - expect((comment as WithLookup).$lookup?.space).toBeUndefined() + expect(comment.$lookup?.space).toBeUndefined() attempt++ } } @@ -433,10 +433,10 @@ describe('query', () => { const comment = result[0] if (comment !== undefined) { if (attempt > 0) { - expect(((comment as WithLookup).$lookup?.attachedTo as WithLookup)?.$lookup?.space?._id).toEqual(futureSpace._id) + expect((comment.$lookup?.attachedTo as WithLookup)?.$lookup?.space?._id).toEqual(futureSpace._id) resolve(null) } else { - expect(((comment as WithLookup).$lookup?.attachedTo as WithLookup)?.$lookup?.space).toBeUndefined() + expect((comment.$lookup?.attachedTo as WithLookup)?.$lookup?.space).toBeUndefined() attempt++ } } @@ -466,7 +466,7 @@ describe('query', () => { (result) => { const comment = result[0] if (comment !== undefined) { - expect(((comment as WithLookup).$lookup as any)?.comments).toHaveLength(attempt++) + expect((comment.$lookup as any)?.comments).toHaveLength(attempt++) } if (attempt === childLength) { resolve(null) @@ -505,10 +505,10 @@ describe('query', () => { const comment = result[0] if (comment !== undefined) { if (attempt > 0) { - expect((comment as WithLookup).$lookup?.space).toBeUndefined() + expect(comment.$lookup?.space).toBeUndefined() resolve(null) } else { - expect(((comment as WithLookup).$lookup?.space as Doc)?._id).toEqual(futureSpace) + expect((comment.$lookup?.space as Doc)?._id).toEqual(futureSpace) attempt++ } } @@ -546,10 +546,10 @@ describe('query', () => { const comment = result[0] if (comment !== undefined) { if (attempt > 0) { - expect(((comment as WithLookup).$lookup?.attachedTo as WithLookup)?.$lookup?.space).toBeUndefined() + expect((comment.$lookup?.attachedTo as WithLookup)?.$lookup?.space).toBeUndefined() resolve(null) } else { - expect((((comment as WithLookup).$lookup?.attachedTo as WithLookup)?.$lookup?.space as Doc)?._id).toEqual(futureSpace) + expect(((comment.$lookup?.attachedTo as WithLookup)?.$lookup?.space as Doc)?._id).toEqual(futureSpace) attempt++ } } @@ -586,7 +586,7 @@ describe('query', () => { (result) => { const comment = result[0] if (comment !== undefined) { - expect(((comment as WithLookup).$lookup as any)?.comments).toHaveLength(childLength - attempt) + expect((comment.$lookup as any)?.comments).toHaveLength(childLength - attempt) attempt++ } if (attempt === childLength) { @@ -624,7 +624,7 @@ describe('query', () => { (result) => { const comment = result[0] if (comment !== undefined) { - expect(((comment as WithLookup).$lookup?.space as Space).name).toEqual(attempt.toString()) + expect((comment.$lookup?.space as Space).name).toEqual(attempt.toString()) } if (attempt > 0) { resolve(null) @@ -665,7 +665,7 @@ describe('query', () => { (result) => { const comment = result[0] if (comment !== undefined) { - expect((((comment as WithLookup).$lookup?.attachedTo as WithLookup)?.$lookup?.space as Space).name).toEqual(attempt.toString()) + expect(((comment.$lookup?.attachedTo as WithLookup)?.$lookup?.space as Space).name).toEqual(attempt.toString()) } if (attempt > 0) { resolve(null) @@ -700,7 +700,7 @@ describe('query', () => { (result) => { const comment = result[0] if (comment !== undefined) { - expect((((comment as WithLookup).$lookup as any)?.comments[0] as AttachedComment).message).toEqual(attempt.toString()) + expect(((comment.$lookup as any)?.comments[0] as AttachedComment).message).toEqual(attempt.toString()) } if (attempt > 0) { resolve(null) diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 95c0677946..c982a7b7a8 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -118,7 +118,7 @@ export class LiveQuery extends TxProcessor implements Client { query( _class: Ref>, query: DocumentQuery, - callback: (result: T[]) => void, + callback: (result: FindResult) => void, options?: FindOptions ): () => void { const result = this.client.findAll(_class, query, options) diff --git a/packages/theme/styles/_layouts.scss b/packages/theme/styles/_layouts.scss index f43ae247c3..818a36801e 100644 --- a/packages/theme/styles/_layouts.scss +++ b/packages/theme/styles/_layouts.scss @@ -324,6 +324,7 @@ p:last-child { margin-block-end: 0; } .pl-2 { padding-left: .5rem; } .pl-4 { padding-left: 1rem; } +.pl-8 { padding-left: 2rem; } .pr-1 { padding-right: .25rem; } .pr-2 { padding-right: .5rem; } .pr-4 { padding-right: 1rem; } diff --git a/plugins/chunter-assets/assets/icons.svg b/plugins/chunter-assets/assets/icons.svg index f5b9662007..9f7fd3c7d6 100644 --- a/plugins/chunter-assets/assets/icons.svg +++ b/plugins/chunter-assets/assets/icons.svg @@ -8,4 +8,7 @@ + + + diff --git a/plugins/chunter-assets/lang/en.json b/plugins/chunter-assets/lang/en.json index 21a420ba64..5be5f808ff 100644 --- a/plugins/chunter-assets/lang/en.json +++ b/plugins/chunter-assets/lang/en.json @@ -27,6 +27,7 @@ "RepliesCount": "{replies, plural, =1 {# reply} other {# replies}}", "Topic": "Topic", "Thread": "Thread", + "Threads": "Threads", "New": "New", "MarkUnread": "Mark unread", "GetNewReplies": "Get notified about new replies", @@ -35,6 +36,8 @@ "UnpinMessage": "Unpin message", "Pinned": "Pinned:", "EditMessage": "Edit message", - "DeleteMessage": "Delete message" + "DeleteMessage": "Delete message", + "AndYou": "{participants, plural, =0 {Just you} other {and you}}", + "ShowMoreReplies": "Show {count} more replies" } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/ru.json b/plugins/chunter-assets/lang/ru.json index b980b95481..abf52dd6de 100644 --- a/plugins/chunter-assets/lang/ru.json +++ b/plugins/chunter-assets/lang/ru.json @@ -26,6 +26,7 @@ "LastReply": "Последний ответ", "RepliesCount": "{replies, plural, =1 {# ответ} =2 {# ответа} =3 {# ответа} =4 {# ответа} other {# ответов}}", "Thread": "Обсуждение", + "Threads": "Обсуждения", "New": "Новое", "MarkUnread": "Отметить как непрочитанное", "GetNewReplies": "Получать уведомления о новых ответах", @@ -34,6 +35,8 @@ "UnpinMessage": "Открепить сообщение", "Pinned": "Закреплено:", "EditMessage": "Редактировать сообщение", - "DeleteMessage": "Удалить сообщение" + "DeleteMessage": "Удалить сообщение", + "AndYou": "{participants, plural, =0 {Только вы} other {и вы}}", + "ShowMoreReplies": "{count, plural, =3 {Показать еще # ответа} =4 {Показать еще # ответа} other {Показать еще # ответов}}" } } \ No newline at end of file diff --git a/plugins/chunter-assets/src/index.ts b/plugins/chunter-assets/src/index.ts index 2cb719865b..b222700a30 100644 --- a/plugins/chunter-assets/src/index.ts +++ b/plugins/chunter-assets/src/index.ts @@ -20,6 +20,7 @@ const icons = require('../assets/icons.svg') as string // eslint-disable-line loadMetadata(chunter.icon, { Chunter: `${icons}#chunter`, Hashtag: `${icons}#hashtag`, + Thread: `${icons}#thread`, Lock: `${icons}#lock` }) diff --git a/plugins/chunter-resources/src/components/Channel.svelte b/plugins/chunter-resources/src/components/Channel.svelte index 8e9699143e..00cc4dbb24 100644 --- a/plugins/chunter-resources/src/components/Channel.svelte +++ b/plugins/chunter-resources/src/components/Channel.svelte @@ -107,7 +107,7 @@ let newMessagesPos: number = -1 -
+
{#if messages} {#each messages as message, i (message._id)} {#if newMessagesPos === i} @@ -117,10 +117,3 @@ {/each} {/if}
- - diff --git a/plugins/chunter-resources/src/components/ChannelPresenter.svelte b/plugins/chunter-resources/src/components/ChannelPresenter.svelte index 97e5b1c16e..7ed2ba198d 100644 --- a/plugins/chunter-resources/src/components/ChannelPresenter.svelte +++ b/plugins/chunter-resources/src/components/ChannelPresenter.svelte @@ -1,15 +1,14 @@ @@ -17,7 +16,7 @@ import type { Channel } from '@anticrm/chunter' import { Ref, Space } from '@anticrm/core' import { getClient } from '@anticrm/presentation' - import { getCurrentLocation, Icon, navigate } from '@anticrm/ui' + import { getCurrentLocation, Icon, locationToUrl } from '@anticrm/ui' import chunter from '../plugin' export let value: Channel @@ -25,24 +24,28 @@ $: icon = client.getHierarchy().getClass(value._class).icon - function selectSpace (id: Ref) { + function getLink (id: Ref): string { const loc = getCurrentLocation() loc.path[1] = chunter.app.Chunter loc.path[2] = id loc.path.length = 3 loc.fragment = undefined - navigate(loc) + return locationToUrl(loc) } + + $: link = getLink(value._id) -
{ - selectSpace(value._id) - }} -> - {#if icon} - - {/if} - {value.name} -
+{#if value} + +
+ {#if icon} + + {/if} +
+ {value.name} +
+{/if} diff --git a/plugins/chunter-resources/src/components/ChannelSeparator.svelte b/plugins/chunter-resources/src/components/ChannelSeparator.svelte index 4e8337b138..0fc289b697 100644 --- a/plugins/chunter-resources/src/components/ChannelSeparator.svelte +++ b/plugins/chunter-resources/src/components/ChannelSeparator.svelte @@ -23,8 +23,8 @@ export let isNew: boolean = false -
-