From 7f9feacd264915df92d14399dc9c1aa5cb4d22e7 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sun, 26 May 2019 14:15:35 -0400 Subject: prevent showing pinned statuses twice --- src/components/timeline/timeline.js | 10 +++++++++- src/components/timeline/timeline.vue | 2 +- src/components/user_profile/user_profile.vue | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 5e24bd15..55602c7b 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -11,7 +11,8 @@ const Timeline = { 'userId', 'tag', 'embedded', - 'count' + 'count', + 'excludedStatusIds' ], data () { return { @@ -39,6 +40,13 @@ const Timeline = { body: ['timeline-body'].concat(!this.embedded ? ['panel-body'] : []), footer: ['timeline-footer'].concat(!this.embedded ? ['panel-footer'] : []) } + }, + statuses () { + if (this.excludedStatusIds && this.excludedStatusIds.length > 0) { + return this.timeline.visibleStatuses && this.timeline.visibleStatuses.filter(status => !this.excludedStatusIds.includes(status.id)) + } else { + return this.timeline.visibleStatuses + } } }, components: { diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index 1fc52083..623f65d7 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -29,7 +29,7 @@
Date: Fri, 19 Jul 2019 21:48:09 -0400 Subject: update prop name --- src/components/timeline/timeline.js | 6 +++--- src/components/user_profile/user_profile.vue | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 55602c7b..7c8a761a 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -12,7 +12,7 @@ const Timeline = { 'tag', 'embedded', 'count', - 'excludedStatusIds' + 'pinnedStatusIds' ], data () { return { @@ -42,8 +42,8 @@ const Timeline = { } }, statuses () { - if (this.excludedStatusIds && this.excludedStatusIds.length > 0) { - return this.timeline.visibleStatuses && this.timeline.visibleStatuses.filter(status => !this.excludedStatusIds.includes(status.id)) + if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) { + return this.timeline.visibleStatuses && this.timeline.visibleStatuses.filter(status => !this.pinnedStatusIds.includes(status.id)) } else { return this.timeline.visibleStatuses } diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index 1723cffa..81c63d7e 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -34,6 +34,7 @@ :timeline="timeline" :timeline-name="'user'" :user-id="userId" + :pinned-status-ids="user.pinnedStatuseIds" />
Date: Fri, 19 Jul 2019 22:40:37 -0400 Subject: move pinned statuses showing logic in timeline --- src/components/timeline/timeline.vue | 12 ++++++++++++ src/components/user_profile/user_profile.vue | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index 623f65d7..9990f20a 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -27,6 +27,18 @@
+
+ +
-
- -
Date: Fri, 19 Jul 2019 22:46:11 -0400 Subject: put two loops in one parent --- src/components/timeline/timeline.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index 9990f20a..4337ac36 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -31,15 +31,13 @@ -
-
Date: Fri, 19 Jul 2019 22:47:40 -0400 Subject: update prop syntax --- src/components/user_profile/user_profile.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index f4b284e2..fc745d1a 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -20,7 +20,7 @@ :embedded="true" :title="$t('user_profile.timeline_title')" :timeline="timeline" - :timeline-name="'user'" + timeline-name="user" :user-id="userId" :pinned-status-ids="user.pinnedStatuseIds" /> -- cgit v1.2.3-70-g09d2 From 876c6de8066d9ac708bb0cd8e4d4c5e60f9502a6 Mon Sep 17 00:00:00 2001 From: taehoon Date: Fri, 19 Jul 2019 22:49:29 -0400 Subject: fix typos --- src/components/user_profile/user_profile.vue | 2 +- src/modules/users.js | 6 +++--- src/services/entity_normalizer/entity_normalizer.service.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index fc745d1a..e862440e 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -22,7 +22,7 @@ :timeline="timeline" timeline-name="user" :user-id="userId" - :pinned-status-ids="user.pinnedStatuseIds" + :pinned-status-ids="user.pinnedStatusIds" />
{ output.statuses_count = data.statuses_count output.friendIds = [] output.followerIds = [] - output.pinnedStatuseIds = [] + output.pinnedStatusIds = [] if (data.pleroma) { output.follow_request_count = data.pleroma.follow_request_count -- cgit v1.2.3-70-g09d2 From 0f8ace483649c1da66a1270373a3b95683ff9a0b Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 20 Jul 2019 16:54:30 -0400 Subject: update status eliminating logic --- src/components/timeline/timeline.js | 14 ++++++++++---- src/components/timeline/timeline.vue | 16 +++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 7c8a761a..b1413591 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -41,12 +41,18 @@ const Timeline = { footer: ['timeline-footer'].concat(!this.embedded ? ['panel-footer'] : []) } }, - statuses () { + // id map of statuses which need to be hidden in the main list due to pinning logic + excludedStatusIdsObject () { + const result = {} if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) { - return this.timeline.visibleStatuses && this.timeline.visibleStatuses.filter(status => !this.pinnedStatusIds.includes(status.id)) - } else { - return this.timeline.visibleStatuses + for (let status of this.timeline.visibleStatuses) { + if (this.pinnedStatusIds.indexOf(status.id) === -1) { + break + } + result[status.id] = true + } } + return result } }, components: { diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index 4337ac36..0cb4b3ef 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -38,13 +38,15 @@ :show-pinned="true" /> - +
-- cgit v1.2.3-70-g09d2 From 53c9517a4aeae1158a95e3b9c6d6d89e3a7e0ee9 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 24 Jul 2019 22:42:06 -0400 Subject: use array.includes instead of array.indexOf --- src/components/timeline/timeline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index b1413591..a5c6418b 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -46,7 +46,7 @@ const Timeline = { const result = {} if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) { for (let status of this.timeline.visibleStatuses) { - if (this.pinnedStatusIds.indexOf(status.id) === -1) { + if (!this.pinnedStatusIds.includes(status.id)) { break } result[status.id] = true -- cgit v1.2.3-70-g09d2 From 65ef03931661561db0791ee7d560292dda6b7d48 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 25 Jul 2019 08:03:41 -0400 Subject: add unit test for elimination logic --- src/components/timeline/timeline.js | 28 +++++++++++++++++----------- test/unit/specs/components/timeline.spec.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 test/unit/specs/components/timeline.spec.js (limited to 'src') diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index a5c6418b..aac3869f 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -1,7 +1,20 @@ import Status from '../status/status.vue' import timelineFetcher from '../../services/timeline_fetcher/timeline_fetcher.service.js' import Conversation from '../conversation/conversation.vue' -import { throttle } from 'lodash' +import { throttle, keyBy } from 'lodash' + +export const getExcludedStatusIdsByPinning = (statuses, pinnedStatusIds) => { + const ids = [] + if (pinnedStatusIds && pinnedStatusIds.length > 0) { + for (let status of statuses) { + if (!pinnedStatusIds.includes(status.id)) { + break + } + ids.push(status.id) + } + } + return ids +} const Timeline = { props: [ @@ -43,16 +56,9 @@ const Timeline = { }, // id map of statuses which need to be hidden in the main list due to pinning logic excludedStatusIdsObject () { - const result = {} - if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) { - for (let status of this.timeline.visibleStatuses) { - if (!this.pinnedStatusIds.includes(status.id)) { - break - } - result[status.id] = true - } - } - return result + const ids = getExcludedStatusIdsByPinning(this.timeline.visibleStatuses, this.pinnedStatusIds) + // Convert id array to object + return keyBy(ids, id => id) } }, components: { diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js new file mode 100644 index 00000000..b13d3e20 --- /dev/null +++ b/test/unit/specs/components/timeline.spec.js @@ -0,0 +1,17 @@ +import { getExcludedStatusIdsByPinning } from 'src/components/timeline/timeline.js' +import { difference } from 'lodash' + +describe('Timeline', () => { + describe('getExcludedStatusIdsByPinning', () => { + it('should not return unpinned status ids', () => { + const statuses = [ + { id: 1 }, + { id: 2 }, + { id: 3 }, + { id: 4 } + ] + const pinnedStatusIds = [1, 3] + expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), pinnedStatusIds)).to.eql([]) + }) + }) +}) \ No newline at end of file -- cgit v1.2.3-70-g09d2