Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intuitive input bindings #4970

Merged
merged 8 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import FtSelect from '../../components/ft-select/ft-select.vue'
import FtToggleSwitch from '../../components/ft-toggle-switch/ft-toggle-switch.vue'
import {
showToast,
ctrlFHandler,
getIconForSortPreference
} from '../../helpers/utils'

Expand Down Expand Up @@ -199,12 +200,13 @@ export default defineComponent({
},
mounted: function () {
this.lastActiveElement = document.activeElement

this.updateQueryDebounce = debounce(this.updateQuery, 500)
// User might want to search first if they have many playlists
this.$refs.searchBar.focus()
document.addEventListener('keydown', this.keyboardShortcutHandler)
},
beforeDestroy() {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
this.lastActiveElement?.focus()
},
methods: {
Expand Down Expand Up @@ -270,6 +272,10 @@ export default defineComponent({
this.query = query
},

keyboardShortcutHandler: function (event) {
ctrlFHandler(event, this.$refs.searchBar)
},

getIconForSortPreference: (s) => getIconForSortPreference(s),

...mapActions([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
:value="translatedProfileName"
:show-action-button="false"
@input="e => profileName = e"
@keydown.enter.native="saveProfile"
/>
</div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ft-select/ft-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<label
class="select-label"
:for="sanitizedId ?? sanitizedPlaceholder"
:hidden="disabled"
v-if="!disabled"

Check warning on line 31 in src/renderer/components/ft-select/ft-select.vue

View workflow job for this annotation

GitHub Actions / lint

Attribute "v-if" should go before ":for"
kommunarr marked this conversation as resolved.
Show resolved Hide resolved
>
<font-awesome-icon
:icon="icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
input-type="password"
:value="password"
@input="e => password = e"
@keydown.enter.native="handleSetPassword"
/>
<ft-button
class="centerButton"
Expand Down
15 changes: 3 additions & 12 deletions src/renderer/components/playlist-info/playlist-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FtInput from '../ft-input/ft-input.vue'
import FtPrompt from '../ft-prompt/ft-prompt.vue'
import FtButton from '../ft-button/ft-button.vue'
import {
ctrlFHandler,
formatNumber,
showToast,
} from '../../helpers/utils'
Expand Down Expand Up @@ -411,19 +412,9 @@ export default defineComponent({
this.$emit('search-video-query-change', query)
},

keyboardShortcutHandler(event) {
switch (event.key) {
case 'F':
case 'f':
if (this.searchVideoModeAllowed && ((process.platform !== 'darwin' && event.ctrlKey) || (process.platform === 'darwin' && event.metaKey))) {
nextTick(() => {
// Some elements only present after rendering update
this.$refs.searchInput.focus()
})
}
}
keyboardShortcutHandler: function (event) {
ctrlFHandler(event, this.$refs.searchInput)
},

...mapActions([
'showAddToPlaylistPromptForManyVideos',
'updatePlaylist',
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/playlist-info/playlist-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
:show-label="false"
:value="newTitle"
@input="(input) => (newTitle = input)"
@keydown.enter.native="savePlaylistInfo"
/>
<h2
v-else
Expand Down Expand Up @@ -66,6 +67,7 @@
:show-label="false"
:value="newDescription"
@input="(input) => newDescription = input"
@keydown.enter.native="savePlaylistInfo"
/>
<p
v-else
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/proxy-settings/proxy-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
:show-label="true"
:value="proxyHostname"
@input="handleUpdateProxyHostname"
@keydown.enter.native="testProxy"
/>
<ft-input
:placeholder="$t('Settings.Proxy Settings.Proxy Port Number')"
:show-action-button="false"
:show-label="true"
:value="proxyPort"
@input="handleUpdateProxyPort"
@keydown.enter.native="testProxy"
/>
</ft-flex-box>
<p
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IpcChannels } from '../../constants'
import FtToastEvents from '../components/ft-toast/ft-toast-events'
import i18n from '../i18n/index'
import router from '../router/index'
import { nextTick } from 'vue'

// allowed characters in channel handle: A-Z, a-z, 0-9, -, _, .
// https://support.google.com/youtube/answer/11585688#change_handle
Expand Down Expand Up @@ -862,3 +863,13 @@ export async function fetchWithTimeout(timeoutMs, input, init) {
}
}
}

export function ctrlFHandler(event, inputElement) {
switch (event.key) {
case 'F':
case 'f':
if (((process.platform !== 'darwin' && event.ctrlKey) || (process.platform === 'darwin' && event.metaKey))) {
nextTick(() => inputElement?.focus())
}
}
}
9 changes: 9 additions & 0 deletions src/renderer/views/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import autolinker from 'autolinker'
import {
setPublishedTimestampsInvidious,
copyToClipboard,
ctrlFHandler,
extractNumberFromString,
formatNumber,
showToast,
Expand Down Expand Up @@ -435,6 +436,7 @@ export default defineComponent({
},
mounted: function () {
this.isLoading = true
document.addEventListener('keydown', this.keyboardShortcutHandler)

if (this.$route.query.url) {
this.resolveChannelUrl(this.$route.query.url, this.$route.params.currentTab)
Expand All @@ -461,6 +463,9 @@ export default defineComponent({
})
}
},
beforeDestroy() {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
resolveChannelUrl: async function (url, tab = undefined) {
let id
Expand Down Expand Up @@ -1951,6 +1956,10 @@ export default defineComponent({
})
},

keyboardShortcutHandler: function (event) {
ctrlFHandler(event, this.$refs.channelSearchBar)
},

getIconForSortPreference: (s) => getIconForSortPreference(s),

...mapActions([
Expand Down
1 change: 1 addition & 0 deletions src/renderer/views/Channel/Channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@

<ft-input
v-if="showSearchBar"
ref="channelSearchBar"
:placeholder="$t('Channel.Search Channel')"
:show-clear-text-button="true"
class="channelSearch"
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/views/History/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FtElementList from '../../components/ft-element-list/ft-element-list.vue'
import FtButton from '../../components/ft-button/ft-button.vue'
import FtInput from '../../components/ft-input/ft-input.vue'
import FtAutoLoadNextPageWrapper from '../../components/ft-auto-load-next-page-wrapper/ft-auto-load-next-page-wrapper.vue'
import { ctrlFHandler } from '../../helpers/utils'

export default defineComponent({
name: 'History',
Expand Down Expand Up @@ -53,6 +54,7 @@ export default defineComponent({
}
},
mounted: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)
const limit = sessionStorage.getItem('historyLimit')

if (limit !== null) {
Expand All @@ -69,6 +71,9 @@ export default defineComponent({

this.filterHistoryDebounce = debounce(this.filterHistory, 500)
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
increaseLimit: function () {
if (this.query !== '') {
Expand Down Expand Up @@ -113,5 +118,8 @@ export default defineComponent({
this.activeData = filteredQuery.length < this.searchDataLimit ? filteredQuery : filteredQuery.slice(0, this.searchDataLimit)
}
},
keyboardShortcutHandler: function (event) {
ctrlFHandler(event, this.$refs.searchBar)
}
}
})
11 changes: 10 additions & 1 deletion src/renderer/views/SubscribedChannels/SubscribedChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FtInput from '../../components/ft-input/ft-input.vue'
import FtSubscribeButton from '../../components/ft-subscribe-button/ft-subscribe-button.vue'
import { invidiousGetChannelInfo, youtubeImageUrlToInvidious, invidiousImageUrlToInvidious } from '../../helpers/api/invidious'
import { getLocalChannel } from '../../helpers/api/local'
import { ctrlFHandler } from '../../helpers/utils'

export default defineComponent({
name: 'SubscribedChannels',
Expand All @@ -26,7 +27,7 @@ export default defineComponent({
},
thumbnailSize: 176,
ytBaseURL: 'https://yt3.ggpht.com',
errorCount: 0
errorCount: 0,
}
},
computed: {
Expand Down Expand Up @@ -78,8 +79,12 @@ export default defineComponent({
}
},
mounted: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)
this.getSubscription()
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
getSubscription: function () {
this.subscribedChannels = this.activeSubscriptionList.slice().sort((a, b) => {
Expand Down Expand Up @@ -155,6 +160,10 @@ export default defineComponent({
}
},

keyboardShortcutHandler: function (event) {
ctrlFHandler(event, this.$refs.searchBarChannels)
},

...mapActions([
'updateSubscriptionDetails'
])
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/views/UserPlaylists/UserPlaylists.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import FtInput from '../../components/ft-input/ft-input.vue'
import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue'
import FtToggleSwitch from '../../components/ft-toggle-switch/ft-toggle-switch.vue'
import FtAutoLoadNextPageWrapper from '../../components/ft-auto-load-next-page-wrapper/ft-auto-load-next-page-wrapper.vue'
import { getIconForSortPreference } from '../../helpers/utils'
import { ctrlFHandler, getIconForSortPreference } from '../../helpers/utils'

const SORT_BY_VALUES = {
NameAscending: 'name_ascending',
Expand Down Expand Up @@ -184,6 +184,7 @@ export default defineComponent({
},
},
mounted: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)
const limit = sessionStorage.getItem('favoritesLimit')
if (limit !== null) {
this.dataLimit = limit
Expand All @@ -200,6 +201,9 @@ export default defineComponent({

this.filterPlaylistDebounce = debounce(this.filterPlaylist, 500)
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
increaseLimit: function () {
if (this.query !== '') {
Expand Down Expand Up @@ -243,6 +247,10 @@ export default defineComponent({
})
},

keyboardShortcutHandler: function (event) {
ctrlFHandler(event, this.$refs.searchBar)
},

getIconForSortPreference: (s) => getIconForSortPreference(s),

...mapActions([
Expand Down
Loading