mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-01 12:26:02 +03:00
Better defaults if prompt becomes invalid
This commit is contained in:
parent
d80475e563
commit
53abdffb5c
@ -30,7 +30,9 @@ export class PromptService {
|
||||
selectedBranchPrompt(projectId: string): Prompt | undefined {
|
||||
const id = get(this.selectedBranchPromptId(projectId));
|
||||
|
||||
return get(this.branchPrompts.userPrompts).find((userPrompt) => userPrompt.id == id)?.prompt;
|
||||
if (!id) return;
|
||||
|
||||
return this.findPrompt(get(this.branchPrompts.userPrompts), id);
|
||||
}
|
||||
|
||||
selectedCommitPromptId(projectId: string): Persisted<string | undefined> {
|
||||
@ -39,9 +41,19 @@ export class PromptService {
|
||||
|
||||
selectedCommitPrompt(projectId: string): Prompt | undefined {
|
||||
const id = get(this.selectedCommitPromptId(projectId));
|
||||
console.log(id);
|
||||
|
||||
return get(this.commitPrompts.userPrompts).find((userPrompt) => userPrompt.id == id)?.prompt;
|
||||
if (!id) return;
|
||||
|
||||
return this.findPrompt(get(this.commitPrompts.userPrompts), id);
|
||||
}
|
||||
|
||||
findPrompt(prompts: UserPrompt[], promptId: string) {
|
||||
const prompt = prompts.find((userPrompt) => userPrompt.id == promptId)?.prompt;
|
||||
|
||||
if (!prompt) return;
|
||||
if (this.promptMissingContent(prompt)) return;
|
||||
|
||||
return prompt;
|
||||
}
|
||||
|
||||
promptEquals(prompt1: Prompt, prompt2: Prompt) {
|
||||
|
@ -41,7 +41,8 @@
|
||||
}
|
||||
|
||||
function initializeForm(form: HTMLFormElement) {
|
||||
if ($selectedPromptId) {
|
||||
// If the selectedPromptId is present and cooresponds to a valid prompt
|
||||
if ($selectedPromptId && promptService.findPrompt($userPrompts, $selectedPromptId)) {
|
||||
form.prompt.value = $selectedPromptId;
|
||||
} else {
|
||||
form.prompt.value = defaultId;
|
||||
|
Loading…
Reference in New Issue
Block a user