directly update edited content
This commit is contained in:
@@ -13,14 +13,18 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
||||
return file?.path ?? ''
|
||||
})
|
||||
|
||||
const { render, getRawContent: getRawContentFromFile } = useMarkdown(
|
||||
toValue(sha)
|
||||
)
|
||||
const {
|
||||
render,
|
||||
renderFromUTF8,
|
||||
getRawContent: getRawContentFromFile
|
||||
} = useMarkdown(toValue(sha))
|
||||
const { getCachedNote, saveCacheNote } = prepareNoteCache(toValue(sha))
|
||||
const fromCache = ref(false)
|
||||
|
||||
const content = ref('')
|
||||
const rawContent = ref('')
|
||||
const content = computed(() =>
|
||||
rawContent.value ? renderFromUTF8(rawContent.value) : ''
|
||||
)
|
||||
|
||||
const getCachedFileContent = async (): Promise<string | null> => {
|
||||
const cachedNote = await getCachedNote()
|
||||
@@ -72,7 +76,6 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
||||
}
|
||||
|
||||
rawContent.value = getRawContentFromFile(fileContent)
|
||||
content.value = render(fileContent)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -83,6 +86,7 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
||||
getRawContent,
|
||||
getContent,
|
||||
getCachedFileContent,
|
||||
fromCache
|
||||
fromCache,
|
||||
saveCacheNote
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,19 @@ import { confirmMessage, errorMessage } from '@/utils/notif'
|
||||
|
||||
export const useGitHubUpdate = ({
|
||||
user,
|
||||
repo,
|
||||
sha
|
||||
repo
|
||||
}: {
|
||||
user: string
|
||||
repo: string
|
||||
sha: string
|
||||
}) => {
|
||||
const updateFile = async ({
|
||||
content,
|
||||
path
|
||||
path,
|
||||
sha
|
||||
}: {
|
||||
content: string
|
||||
path: string
|
||||
sha: string
|
||||
}) => {
|
||||
try {
|
||||
const octokit = await getOctokit()
|
||||
@@ -35,7 +35,9 @@ export const useGitHubUpdate = ({
|
||||
|
||||
confirmMessage('file saved on GitHub')
|
||||
|
||||
return response?.data.commit.sha ?? null
|
||||
console.log(response)
|
||||
|
||||
return response?.data.content?.sha ?? null
|
||||
} catch (error) {
|
||||
errorMessage('File could not be saved')
|
||||
}
|
||||
|
||||
@@ -41,15 +41,18 @@ const md = new MarkdownIt({
|
||||
|
||||
export const useMarkdown = (defaultPrefix?: Ref<string> | string) => {
|
||||
const getRawContent = (content: string) => decodeBase64ToUTF8(content)
|
||||
const renderFromUTF8 = (content: string, prefix?: string) =>
|
||||
content
|
||||
? md.render(content, {
|
||||
docId: defaultPrefix ? toValue(defaultPrefix) : prefix ?? ''
|
||||
})
|
||||
: ''
|
||||
|
||||
return {
|
||||
toHTML: (content: string) => (content ? md.render(content) : ''),
|
||||
render: (content: string, prefix?: string) =>
|
||||
content
|
||||
? md.render(decodeBase64ToUTF8(content), {
|
||||
docId: defaultPrefix ? toValue(defaultPrefix) : prefix ?? ''
|
||||
})
|
||||
: '',
|
||||
renderFromUTF8(decodeBase64ToUTF8(content), prefix),
|
||||
renderFromUTF8,
|
||||
getRawContent
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user