Skip to content

Commit bccab51

Browse files
committed
Make GitAction.title async internally (#169)
1 parent 3609667 commit bccab51

12 files changed

Lines changed: 30 additions & 16 deletions

File tree

src/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ interface GitAction extends ConfigGitAction {
116116
/** Set empty string to disable */
117117
storage_key: string
118118
params: () => Promise<GitActionParam[]>
119+
title: () => Promise<string>
119120
}
120121

121122
interface HistoryEntry {

tsconfig.base.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"outDir": "/dev/null",
1313
"skipLibCheck": true,
1414
"baseUrl": ".",
15-
"types": ["vite/client"],
1615
"moduleResolution": "bundler",
1716
"module": "ESNext",
1817
"target": "ESNext",

web/src/components/GitActionButton.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44
<div v-if="git_action.icon" class="icon center">
55
<i :class="'codicon-'+git_action.icon" class="codicon" />
66
</div>
7-
<div v-if="git_action.title" class="title">
8-
{{ git_action.title }}
7+
<div v-if="title" class="title">
8+
{{ title }}
99
</div>
1010
</button>
1111
</template>
1212
<script setup>
1313
import { selected_git_action } from '../data/store'
14+
import vue_resolved from '../utils/vue-resolved'
1415
defineOptions({
1516
inheritAttrs: false,
1617
})
17-
defineProps({
18+
let props = defineProps({
1819
git_action: {
1920
/** @type {Vue.PropType<GitAction>} */
2021
type: Object,
2122
required: true,
2223
},
2324
})
25+
let title = vue_resolved(props.git_action.title())
2426
</script>
2527
<style>
2628

web/src/components/RefTip.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ let context_menu_provider = computed(() => () => {
7777
if (branch.value)
7878
return to_context_menu_entries(branch_actions(branch.value).value)
7979
.concat({
80-
label: 'Show',
80+
label: () => Promise.resolve('Show'),
8181
icon: 'eye',
8282
action() {
8383
if (branch.value)

web/src/data/store/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function apply_action_replacements(actions, replacements = []) {
2424
, Promise.resolve(txt))
2525
return actions.map(action => ({
2626
...action,
27-
title: apply_string_replacements(action.title),
27+
title: () => apply_promise_replacements(apply_string_replacements(action.title || '')),
2828
description: apply_string_replacements(action.description || ''),
2929
// This should better also include the action placement (global, branch, stash, ...),
3030
// also 'global' vs. replacements doesn't make any sense in namespace.

web/src/data/store/repo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export let log_action = {
4848
storage_key: 'main-log',
4949
immediate: false,
5050
params: () => Promise.resolve([]),
51-
title: '',
51+
title: () => Promise.resolve(''),
5252
}
5353

5454
/** `fetch_branches` should be true usually because otherwise branch data is missing such as tracking_remote_names */

web/src/directives/context-menu.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @typedef {{label:string,icon?:string,action:()=>any}} ContextMenuEntry */
1+
/** @typedef {{label:()=>Promise<string>,icon?:string,action:()=>any}} ContextMenuEntry */
22
/**
33
@typedef {{
44
oncontextmenu: (this: HTMLElement, ev: MouseEvent) => any
@@ -57,7 +57,7 @@ function set_context_menu(/** @type {HTMLElement} */ el, /** @type {(ev: MouseEv
5757
let wrapper_el = null
5858

5959
// The element(s) created by this is quite similar to the template of <git-action-button>
60-
function build_context_menu(/** @type {MouseEvent} */ event) {
60+
async function build_context_menu(/** @type {MouseEvent} */ event) {
6161
let entries = entries_provider(event)
6262
if (! entries || wrapper_el)
6363
return
@@ -66,7 +66,7 @@ function set_context_menu(/** @type {HTMLElement} */ el, /** @type {(ev: MouseEv
6666
wrapper_el.classList.add('context-menu-wrapper')
6767
wrapper_el.style.setProperty('left', event.clientX + 'px')
6868
wrapper_el.style.setProperty('top', event.clientY + 'px')
69-
entries.forEach((entry) => {
69+
for (let entry of entries) {
7070
let entry_el = document.createElement('li')
7171
entry_el.setAttribute('role', 'button')
7272
entry_el.setAttribute('tabindex', '-1')
@@ -75,15 +75,15 @@ function set_context_menu(/** @type {HTMLElement} */ el, /** @type {(ev: MouseEv
7575
if (entry.icon)
7676
icon_el.classList.add('codicon', `codicon-${entry.icon}`)
7777
let label_el = document.createElement('span')
78-
label_el.textContent = entry.label
78+
label_el.textContent = await entry.label()
7979
entry_el.appendChild(icon_el)
8080
entry_el.appendChild(label_el)
8181
entry_el.onfocus = () => {
8282
entry.action()
8383
remove_all_context_menus()
8484
}
8585
wrapper_el?.appendChild(entry_el)
86-
})
86+
}
8787
document.body.appendChild(wrapper_el)
8888
}
8989

web/src/utils/vue-resolved.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ref } from 'vue'
2+
3+
export default (/** @type {Promise<any> | undefined} */ promise) => {
4+
if (! promise)
5+
return ''
6+
let resolved = ref('Loading...')
7+
promise.then(v => resolved.value = v)
8+
return resolved
9+
}

web/src/views/main-view/History.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let history_mapped = computed(() =>
5656
? filtered_commits.value?.find((commit) =>
5757
commit.hash === entry.value) : undefined,
5858
git_action: entry.type === 'git' ? {
59-
title: 'git ' + entry.value,
59+
title: () => Promise.resolve('git ' + entry.value),
6060
args: entry.value,
6161
description: 'History entry',
6262
icon: 'history',

web/src/views/main-view/SelectedGitAction.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div class="selected-git-action">
33
<h2>
4-
<template v-if="selected_git_action?.title">
5-
{{ selected_git_action.title }} -&nbsp;
4+
<template v-if="title">
5+
{{ title }} -&nbsp;
66
</template>
77
{{ selected_git_action?.description }}
88
</h2>
@@ -23,13 +23,15 @@
2323
<script setup>
2424
import { ref } from 'vue'
2525
import { selected_git_action, trigger_main_refresh } from '../../data/store'
26+
import vue_resolved from '../../utils/vue-resolved'
2627
2728
let keep_open = ref(false)
2829
2930
function success() {
3031
if (! keep_open.value)
3132
selected_git_action.value = null
3233
}
34+
let title = vue_resolved(selected_git_action.value?.title())
3335
</script>
3436
<style>
3537
.selected-git-action {

0 commit comments

Comments
 (0)