From 23b9d1eaa31efc83705288409e5993279ae969e6 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 3 Apr 2019 22:38:48 -0400 Subject: rename selectable_row to selectable_list --- src/components/selectable_list/selectable_list.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/components/selectable_list/selectable_list.vue (limited to 'src/components/selectable_list/selectable_list.vue') diff --git a/src/components/selectable_list/selectable_list.vue b/src/components/selectable_list/selectable_list.vue new file mode 100644 index 00000000..11853672 --- /dev/null +++ b/src/components/selectable_list/selectable_list.vue @@ -0,0 +1,10 @@ + + + + + -- cgit v1.2.3-70-g09d2 From d9b3f5be4733f0eef4d3c8dff982224cd1a5303e Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 3 Apr 2019 22:48:00 -0400 Subject: use SelectableList for blocks/mutes list --- src/components/selectable_list/selectable_list.js | 11 +++++------ src/components/selectable_list/selectable_list.vue | 18 +++++++++++++++--- src/components/user_settings/user_settings.js | 6 +++--- 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src/components/selectable_list/selectable_list.vue') diff --git a/src/components/selectable_list/selectable_list.js b/src/components/selectable_list/selectable_list.js index cd431eeb..138e63ab 100644 --- a/src/components/selectable_list/selectable_list.js +++ b/src/components/selectable_list/selectable_list.js @@ -4,12 +4,11 @@ const SelectableList = { components: { Checkbox }, - props: ['checked'], - data () { - }, - computed: { - }, - methods: { + props: { + items: { + type: Array, + default: () => [] + } } } diff --git a/src/components/selectable_list/selectable_list.vue b/src/components/selectable_list/selectable_list.vue index 11853672..2e0671ef 100644 --- a/src/components/selectable_list/selectable_list.vue +++ b/src/components/selectable_list/selectable_list.vue @@ -1,10 +1,22 @@ - + diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 2bbb01db..f8742cd4 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -9,7 +9,7 @@ import ScopeSelector from '../scope_selector/scope_selector.vue' import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' import BlockCard from '../block_card/block_card.vue' import MuteCard from '../mute_card/mute_card.vue' -import List from '../list/list.vue' +import SelectableList from '../selectable_list/selectable_list.vue' import EmojiInput from '../emoji-input/emoji-input.vue' import Autosuggest from '../autosuggest/autosuggest.vue' import withSubscription from '../../hocs/with_subscription/with_subscription' @@ -19,13 +19,13 @@ const BlockList = withSubscription({ fetch: (props, $store) => $store.dispatch('fetchBlocks'), select: (props, $store) => get($store.state.users.currentUser, 'blockIds', []), childPropName: 'items' -})(List) +})(SelectableList) const MuteList = withSubscription({ fetch: (props, $store) => $store.dispatch('fetchMutes'), select: (props, $store) => get($store.state.users.currentUser, 'muteIds', []), childPropName: 'items' -})(List) +})(SelectableList) const UserSettings = { data () { -- cgit v1.2.3-70-g09d2 From e0b246375009a4c533d90def0842bd8cf59f78cc Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 3 Apr 2019 23:26:13 -0400 Subject: save selected items to the state --- src/components/selectable_list/selectable_list.js | 25 ++++++++++++++++++++++ src/components/selectable_list/selectable_list.vue | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/components/selectable_list/selectable_list.vue') diff --git a/src/components/selectable_list/selectable_list.js b/src/components/selectable_list/selectable_list.js index 138e63ab..5c01bbab 100644 --- a/src/components/selectable_list/selectable_list.js +++ b/src/components/selectable_list/selectable_list.js @@ -8,6 +8,31 @@ const SelectableList = { items: { type: Array, default: () => [] + }, + getKey: { + type: Function, + default: item => item + } + }, + data () { + return { + selected: [] + } + }, + methods: { + toggle (checked, item) { + const oldChecked = this.isChecked(item) + if (checked !== oldChecked) { + const key = this.getKey(item) + if (checked) { + this.selected.push(key) + } else { + this.selected.splice(this.selected.indexOf(key), 1) + } + } + }, + isChecked (item) { + return this.selected.indexOf(this.getKey(item)) !== -1 } } } diff --git a/src/components/selectable_list/selectable_list.vue b/src/components/selectable_list/selectable_list.vue index 2e0671ef..d7b166bc 100644 --- a/src/components/selectable_list/selectable_list.vue +++ b/src/components/selectable_list/selectable_list.vue @@ -1,7 +1,7 @@