Skip to content

Commit 963a4e7

Browse files
committed
refactor(studio): rename githubFile to remoteFile
1 parent 02d7409 commit 963a4e7

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

src/app/src/components/content/ContentCardReview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async function initializeEditor() {
9090
isLoadingContent.value = true
9191
9292
const localOriginal = props.draftItem.original ? await generateContentFromDocument(props.draftItem.original as DatabaseItem) : null
93-
const gitHubOriginal = props.draftItem.githubFile?.content ? fromBase64ToUTF8(props.draftItem.githubFile.content) : null
93+
const gitHubOriginal = props.draftItem.remoteFile?.content ? fromBase64ToUTF8(props.draftItem.remoteFile.content) : null
9494
const modified = props.draftItem.modified ? await generateContentFromDocument(props.draftItem.modified as DatabasePageItem) : null
9595
9696
isAutomaticFormattingDetected.value = !isEqual(localOriginal, gitHubOriginal)

src/app/src/components/content/ContentEditorCode.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ async function setContent(document: DatabasePageItem) {
116116
currentDocumentId.value = document.id
117117
118118
isAutomaticFormattingDetected.value = false
119-
if (props.draftItem.original && props.draftItem.githubFile?.content) {
119+
if (props.draftItem.original && props.draftItem.remoteFile?.content) {
120120
const localOriginal = await generateContentFromDocument(props.draftItem.original as DatabaseItem)
121-
const gitHubOriginal = fromBase64ToUTF8(props.draftItem.githubFile.content)
121+
const remoteOriginal = props.draftItem.remoteFile.encoding === 'base64' ? fromBase64ToUTF8(props.draftItem.remoteFile.content!) : props.draftItem.remoteFile.content!
122122
123-
isAutomaticFormattingDetected.value = !isEqual(localOriginal, gitHubOriginal)
123+
isAutomaticFormattingDetected.value = !isEqual(localOriginal, remoteOriginal)
124124
}
125125
}
126126
</script>

src/app/src/composables/useDraftBase.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ export function useDraftBase<T extends DatabaseItem | MediaItem>(
3434
}
3535

3636
const fsPath = hostDb.getFileSystemPath(item.id)
37-
const githubFile = await git.fetchFile(joinURL(ghPathPrefix, fsPath), { cached: true }) as GithubFile
37+
const remoteFile = await git.fetchFile(joinURL(ghPathPrefix, fsPath), { cached: true }) as GithubFile
3838

3939
const draftItem: DraftItem<T> = {
4040
id: item.id,
4141
fsPath,
42-
githubFile,
42+
remoteFile,
4343
status: getDraftStatus(item, original),
4444
modified: item,
4545
}
@@ -86,22 +86,22 @@ export function useDraftBase<T extends DatabaseItem | MediaItem>(
8686
fsPath: existingDraftItem.fsPath,
8787
status: DraftStatus.Deleted,
8888
original: existingDraftItem.original,
89-
githubFile: existingDraftItem.githubFile,
89+
remoteFile: existingDraftItem.remoteFile,
9090
}
9191

9292
list.value = list.value.map(item => item.id === id ? deleteDraftItem! : item) as DraftItem<T>[]
9393
}
9494
}
9595
else {
9696
// TODO: check if gh file has been updated
97-
const githubFile = await git.fetchFile(joinURL('content', fsPath), { cached: true }) as GithubFile
97+
const remoteFile = await git.fetchFile(joinURL('content', fsPath), { cached: true }) as GithubFile
9898

9999
deleteDraftItem = {
100100
id,
101101
fsPath,
102102
status: DraftStatus.Deleted,
103103
original: originalDbItem,
104-
githubFile,
104+
remoteFile,
105105
}
106106

107107
list.value.push(deleteDraftItem)

src/app/src/composables/useDraftMedias.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
4141
return {
4242
id: joinURL(TreeRootId.Media, fsPath),
4343
fsPath,
44-
githubFile: undefined,
44+
remoteFile: undefined,
4545
status: DraftStatus.Created,
4646
modified: {
4747
id: joinURL(TreeRootId.Media, fsPath),

src/app/src/types/draft.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface DraftItem<T = DatabaseItem | MediaItem> {
1919
fsPath: string // file path in content directory
2020
status: DraftStatus // status
2121

22-
githubFile?: GithubFile // file fetched on gh
22+
remoteFile?: GithubFile
2323
original?: T
2424
modified?: T
2525
/**

src/app/src/utils/draft.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ export async function checkConflict(draftItem: DraftItem<DatabaseItem | MediaIte
1414
return
1515
}
1616

17-
if (draftItem.status === DraftStatus.Created && draftItem.githubFile) {
17+
if (draftItem.status === DraftStatus.Created && draftItem.remoteFile) {
1818
return {
19-
githubContent: fromBase64ToUTF8(draftItem.githubFile.content!),
19+
githubContent: draftItem.remoteFile.encoding === 'base64' ? fromBase64ToUTF8(draftItem.remoteFile.content!) : draftItem.remoteFile.content!,
2020
localContent: await generateContentFromDocument(draftItem.modified as DatabaseItem) as string,
2121
}
2222
}
2323

2424
// TODO: No GitHub file found (might have been deleted remotely)
25-
if (!draftItem.githubFile || !draftItem.githubFile.content) {
25+
if (!draftItem.remoteFile || !draftItem.remoteFile.content) {
2626
return
2727
}
2828

2929
const localContent = await generateContentFromDocument(draftItem.original as DatabaseItem) as string
30-
const githubContent = fromBase64ToUTF8(draftItem.githubFile.content)
30+
const githubContent = draftItem.remoteFile.encoding === 'base64' ? fromBase64ToUTF8(draftItem.remoteFile.content!) : draftItem.remoteFile.content!
3131
const githubDocument = await generateDocumentFromContent(draftItem.id, githubContent) as DatabaseItem
3232

3333
if (isEqual(draftItem.original as DatabasePageItem, githubDocument as DatabasePageItem)) {

src/app/test/mocks/git.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { vi } from 'vitest'
22
import type { GithubFile } from '../../src/types/git'
33
import type { useGit } from '../../src/composables/useGit'
44

5-
export const createMockGit = (githubFile?: GithubFile): ReturnType<typeof useGit> => ({
6-
fetchFile: vi.fn().mockResolvedValue(githubFile || createMockGithubFile()),
5+
export const createMockGit = (remoteFile?: GithubFile): ReturnType<typeof useGit> => ({
6+
fetchFile: vi.fn().mockResolvedValue(remoteFile || createMockGithubFile()),
77
} as never)
88

99
export const createMockGithubFile = (overrides?: Partial<GithubFile>): GithubFile => ({
10+
provider: 'github',
1011
path: 'content/document.md',
1112
name: 'document.md',
1213
content: 'Test content',

0 commit comments

Comments
 (0)