-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathsubscriptions-tab-ui.js
More file actions
131 lines (122 loc) · 3.47 KB
/
subscriptions-tab-ui.js
File metadata and controls
131 lines (122 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { defineComponent } from 'vue'
import FtLoader from '../ft-loader/ft-loader.vue'
import FtButton from '../ft-button/ft-button.vue'
import FtRefreshWidget from '../ft-refresh-widget/ft-refresh-widget.vue'
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
import FtElementList from '../FtElementList/FtElementList.vue'
import FtChannelBubble from '../ft-channel-bubble/ft-channel-bubble.vue'
import FtAutoLoadNextPageWrapper from '../ft-auto-load-next-page-wrapper/ft-auto-load-next-page-wrapper.vue'
import { KeyboardShortcuts } from '../../../constants'
export default defineComponent({
name: 'SubscriptionsTabUI',
components: {
'ft-loader': FtLoader,
'ft-button': FtButton,
'ft-refresh-widget': FtRefreshWidget,
'ft-flex-box': FtFlexBox,
'ft-element-list': FtElementList,
'ft-channel-bubble': FtChannelBubble,
'ft-auto-load-next-page-wrapper': FtAutoLoadNextPageWrapper,
},
props: {
isLoading: {
type: Boolean,
default: false
},
videoList: {
type: Array,
default: () => ([])
},
isCommunity: {
type: Boolean,
default: false
},
errorChannels: {
type: Array,
default: () => ([])
},
attemptedFetch: {
type: Boolean,
default: false
},
initialDataLimit: {
type: Number,
default: 100
},
lastRefreshTimestamp: {
type: String,
required: true
},
title: {
type: String,
required: true
}
},
emits: ['refresh'],
data: function () {
return {
dataLimit: 100,
}
},
computed: {
activeVideoList: function () {
if (this.videoList.length < this.dataLimit) {
return this.videoList
} else {
return this.videoList.slice(0, this.dataLimit)
}
},
activeProfile: function () {
return this.$store.getters.getActiveProfile
},
activeSubscriptionList: function () {
return this.activeProfile.subscriptions
},
fetchSubscriptionsAutomatically: function() {
return this.$store.getters.getFetchSubscriptionsAutomatically
}
},
created: function () {
const dataLimit = sessionStorage.getItem('subscriptionLimit')
if (dataLimit !== null) {
this.dataLimit = dataLimit
} else {
this.dataLimit = this.initialDataLimit
}
},
mounted: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
increaseLimit: function () {
this.dataLimit += this.initialDataLimit
sessionStorage.setItem('subscriptionLimit', this.dataLimit)
},
/**
* This function `keyboardShortcutHandler` should always be at the bottom of this file
* @param {KeyboardEvent} event the keyboard event
*/
keyboardShortcutHandler: function (event) {
if (event.ctrlKey || document.activeElement.classList.contains('ft-input')) {
return
}
// Avoid handling events due to user holding a key (not released)
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat
if (event.repeat) { return }
switch (event.key.toLowerCase()) {
case 'f5':
case KeyboardShortcuts.APP.SITUATIONAL.REFRESH:
if (!this.isLoading && this.activeSubscriptionList.length > 0) {
this.$emit('refresh')
}
break
}
},
refresh: function() {
this.$emit('refresh')
}
}
})