Skip to content

Commit 1a7c8f6

Browse files
absidueOothecaPickle
authored andcommitted
Migrate Subscriptions and SubscriptionsTabUi to the composition API (FreeTubeApp#6612)
1 parent 902a08a commit 1a7c8f6

File tree

11 files changed

+381
-385
lines changed

11 files changed

+381
-385
lines changed

src/renderer/components/subscriptions-tab-ui/subscriptions-tab-ui.css renamed to src/renderer/components/SubscriptionsTabUi/SubscriptionsTabUi.css

File renamed without changes.
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<template>
2+
<div>
3+
<FtLoader
4+
v-if="isLoading"
5+
/>
6+
<div
7+
v-if="!isLoading && errorChannels.length !== 0"
8+
>
9+
<h3> {{ $t("Subscriptions.Error Channels") }}</h3>
10+
<FtFlexBox>
11+
<FtChannelBubble
12+
v-for="channel in errorChannels"
13+
:key="channel.id"
14+
:channel-name="channel.name"
15+
:channel-id="channel.id"
16+
:channel-thumbnail="channel.thumbnail"
17+
/>
18+
</FtFlexBox>
19+
</div>
20+
<FtFlexBox
21+
v-if="!isLoading && activeVideoList.length === 0"
22+
>
23+
<p
24+
v-if="!activeProfileHasSubscriptions"
25+
class="message"
26+
>
27+
{{ $t("Subscriptions['Your Subscription list is currently empty. Start adding subscriptions to see them here.']") }}
28+
</p>
29+
<p
30+
v-else-if="!fetchSubscriptionsAutomatically && !attemptedFetch"
31+
class="message"
32+
>
33+
{{ $t("Subscriptions.Disabled Automatic Fetching") }}
34+
</p>
35+
<p
36+
v-else
37+
class="message"
38+
>
39+
{{ isCommunity ? $t("Subscriptions.Empty Posts") : $t("Subscriptions.Empty Channels") }}
40+
</p>
41+
</FtFlexBox>
42+
<FtElementList
43+
v-if="!isLoading && activeVideoList.length > 0"
44+
:data="activeVideoList"
45+
:use-channels-hidden-preference="false"
46+
:display="isCommunity ? 'list' : ''"
47+
/>
48+
<FtAutoLoadNextPageWrapper
49+
v-if="!isLoading && videoList.length > dataLimit"
50+
@load-next-page="increaseLimit"
51+
>
52+
<FtFlexBox>
53+
<FtButton
54+
:label="isCommunity ? $t('Subscriptions.Load More Posts') : $t('Subscriptions.Load More Videos')"
55+
background-color="var(--primary-color)"
56+
text-color="var(--text-with-main-color)"
57+
@click="increaseLimit"
58+
/>
59+
</FtFlexBox>
60+
</FtAutoLoadNextPageWrapper>
61+
62+
<FtRefreshWidget
63+
:disable-refresh="isLoading || !activeProfileHasSubscriptions"
64+
:last-refresh-timestamp="lastRefreshTimestamp"
65+
:title="title"
66+
@click="refresh"
67+
/>
68+
</div>
69+
</template>
70+
71+
<script setup>
72+
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
73+
74+
import FtAutoLoadNextPageWrapper from '../ft-auto-load-next-page-wrapper/ft-auto-load-next-page-wrapper.vue'
75+
import FtButton from '../ft-button/ft-button.vue'
76+
import FtChannelBubble from '../ft-channel-bubble/ft-channel-bubble.vue'
77+
import FtElementList from '../FtElementList/FtElementList.vue'
78+
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
79+
import FtLoader from '../ft-loader/ft-loader.vue'
80+
import FtRefreshWidget from '../ft-refresh-widget/ft-refresh-widget.vue'
81+
82+
import store from '../../store/index'
83+
84+
import { KeyboardShortcuts } from '../../../constants'
85+
86+
const props = defineProps({
87+
isLoading: {
88+
type: Boolean,
89+
default: false
90+
},
91+
videoList: {
92+
type: Array,
93+
default: () => []
94+
},
95+
isCommunity: {
96+
type: Boolean,
97+
default: false
98+
},
99+
errorChannels: {
100+
type: Array,
101+
default: () => []
102+
},
103+
attemptedFetch: {
104+
type: Boolean,
105+
default: false
106+
},
107+
initialDataLimit: {
108+
type: Number,
109+
default: 100
110+
},
111+
lastRefreshTimestamp: {
112+
type: String,
113+
required: true
114+
},
115+
title: {
116+
type: String,
117+
required: true
118+
}
119+
})
120+
121+
const emit = defineEmits(['refresh'])
122+
123+
const subscriptionLimit = sessionStorage.getItem('subscriptionLimit')
124+
125+
const dataLimit = ref(subscriptionLimit !== null ? parseInt(subscriptionLimit) : props.initialDataLimit)
126+
127+
const activeVideoList = computed(() => {
128+
if (props.videoList.length < dataLimit.value) {
129+
return props.videoList
130+
} else {
131+
return props.videoList.slice(0, dataLimit.value)
132+
}
133+
})
134+
135+
const activeProfileHasSubscriptions = computed(() => {
136+
return store.getters.getActiveProfile.subscriptions.length > 0
137+
})
138+
139+
/** @type {import('vue').ComputedRef<boolean>} */
140+
const fetchSubscriptionsAutomatically = computed(() => {
141+
return store.getters.getFetchSubscriptionsAutomatically
142+
})
143+
144+
function increaseLimit() {
145+
dataLimit.value += props.initialDataLimit
146+
sessionStorage.setItem('subscriptionLimit', dataLimit.value.toFixed(0))
147+
}
148+
149+
/**
150+
* @param {KeyboardEvent} event
151+
*/
152+
function keyboardShortcutHandler(event) {
153+
if (event.ctrlKey || document.activeElement.classList.contains('ft-input')) {
154+
return
155+
}
156+
// Avoid handling events due to user holding a key (not released)
157+
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat
158+
if (event.repeat) { return }
159+
160+
switch (event.key.toLowerCase()) {
161+
case 'f5':
162+
case KeyboardShortcuts.APP.SITUATIONAL.REFRESH:
163+
if (!props.isLoading && activeProfileHasSubscriptions.value) {
164+
refresh()
165+
}
166+
break
167+
}
168+
}
169+
170+
onMounted(() => {
171+
document.addEventListener('keydown', keyboardShortcutHandler)
172+
})
173+
174+
onBeforeUnmount(() => {
175+
document.removeEventListener('keydown', keyboardShortcutHandler)
176+
})
177+
178+
function refresh() {
179+
emit('refresh')
180+
}
181+
</script>
182+
183+
<style scoped src="./SubscriptionsTabUi.css" />

src/renderer/components/subscriptions-community/subscriptions-community.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineComponent } from 'vue'
22
import { mapActions, mapMutations } from 'vuex'
3-
import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue'
3+
import SubscriptionsTabUI from '../SubscriptionsTabUi/SubscriptionsTabUi.vue'
44

55
import { copyToClipboard, getRelativeTimeFromDate, showToast } from '../../helpers/utils'
66
import { getLocalChannelCommunity } from '../../helpers/api/local'

src/renderer/components/subscriptions-live/subscriptions-live.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineComponent } from 'vue'
22
import { mapActions, mapMutations } from 'vuex'
3-
import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue'
3+
import SubscriptionsTabUI from '../SubscriptionsTabUi/SubscriptionsTabUi.vue'
44

55
import {
66
getChannelPlaylistId,

src/renderer/components/subscriptions-shorts/subscriptions-shorts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineComponent } from 'vue'
22
import { mapActions, mapMutations } from 'vuex'
3-
import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue'
3+
import SubscriptionsTabUI from '../SubscriptionsTabUi/SubscriptionsTabUi.vue'
44

55
import { parseYouTubeRSSFeed, updateVideoListAfterProcessing } from '../../helpers/subscriptions'
66
import {

src/renderer/components/subscriptions-tab-ui/subscriptions-tab-ui.js

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)