Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion apps/desktop/src/lib/pr/PrDetailsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@

const prTitle = $derived(
new ReactivePRTitle(
project.id,
props.type === 'display',
props.type === 'display' ? props.pr.title : undefined,
commits,
Expand All @@ -115,11 +116,13 @@

const prBody = $derived(
new ReactivePRBody(
project.id,
props.type === 'display',
currentSeries?.description ?? '',
props.type === 'display' ? props.pr.body : undefined,
commits,
templateBody
templateBody,
currentSeries?.name ?? ''
)
);

Expand Down
76 changes: 67 additions & 9 deletions apps/desktop/src/lib/pr/prContent.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,60 @@
import { getEphemeralStorageItem, setEphemeralStorageItem } from '@gitbutler/shared/persisted';
import type { DetailedCommit } from '$lib/vbranches/types';

const PERSITANCE_TIME_MIN = 5;

function getPersistedBodyKey(projectId: string, branchName: string) {
return 'seriesCurrentPRBody_' + projectId + '_' + branchName;
}

function getPersistedTitleKey(projectId: string, branchName: string) {
return 'seriesCurrentPRTitle_' + projectId + '_' + branchName;
}

export function setPersistedPRBody(projectId: string, branchName: string, body: string): void {
const key = getPersistedBodyKey(projectId, branchName);
setEphemeralStorageItem(key, body, PERSITANCE_TIME_MIN);
}

export function getPersistedPRBody(projectId: string, branchName: string): string | undefined {
const key = getPersistedBodyKey(projectId, branchName);
const content = getEphemeralStorageItem(key);

if (typeof content === 'string') {
return content;
}

return undefined;
}

export function setPersistedPRTitle(projectId: string, branchName: string, title: string): void {
const key = getPersistedTitleKey(projectId, branchName);
setEphemeralStorageItem(key, title, PERSITANCE_TIME_MIN);
}

export function getPersistedPRTitle(projectId: string, branchName: string): string | undefined {
const key = getPersistedTitleKey(projectId, branchName);
const content = getEphemeralStorageItem(key);

if (typeof content === 'string') {
return content;
}

return undefined;
}

export class ReactivePRTitle {
value = $state<string>('');
private _value = $state<string>('');

constructor(
private projectId: string,
private isDisplay: boolean,
private existingTitle: string | undefined,
private commits: DetailedCommit[],
private branchName: string
) {
this.value = this.getDefaultTitle();
const persistedTitle = getPersistedPRTitle(projectId, branchName);
this._value = persistedTitle ?? this.getDefaultTitle();
}

private getDefaultTitle(): string {
Expand All @@ -22,22 +67,30 @@ export class ReactivePRTitle {
return this.branchName;
}

get value() {
return this._value;
}

set(value: string) {
this.value = value;
this._value = value;
setPersistedPRTitle(this.projectId, this.branchName, value);
}
}

export class ReactivePRBody {
value = $state<string>('');
private _value = $state<string>('');

constructor(
private projectId: string,
private isDisplay: boolean,
private branchDescription: string | undefined,
private existingBody: string | undefined,
private commits: DetailedCommit[],
private templateBody: string | undefined
private templateBody: string | undefined,
private branchName: string
) {
this.value = this.getDefaultBody();
const persistedBody = getPersistedPRBody(projectId, branchName);
this._value = persistedBody ?? this.getDefaultBody();
}

getDefaultBody(): string {
Expand All @@ -52,15 +105,20 @@ export class ReactivePRBody {
return '';
}

get value() {
return this._value;
}

set(value: string) {
this.value = value;
this._value = value;
setPersistedPRBody(this.projectId, this.branchName, value);
}

append(value: string) {
this.value += value;
this.set(this._value + value);
}

reset() {
this.value = '';
this.set('');
}
}
Loading