♻️ (store) use a store to store readme and files
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
"core-js": "^3.9.0",
|
"core-js": "^3.9.0",
|
||||||
"markdown-it": "^12.0.4",
|
"markdown-it": "^12.0.4",
|
||||||
"nanoid": "^3.1.22",
|
"nanoid": "^3.1.22",
|
||||||
|
"pinia": "^2.0.0-alpha.7",
|
||||||
"pouchdb-adapter-indexeddb": "^7.2.2",
|
"pouchdb-adapter-indexeddb": "^7.2.2",
|
||||||
"pouchdb-browser": "^7.2.2",
|
"pouchdb-browser": "^7.2.2",
|
||||||
"register-service-worker": "^1.7.2",
|
"register-service-worker": "^1.7.2",
|
||||||
|
|||||||
@@ -25,8 +25,6 @@
|
|||||||
v-for="(stackedNote, index) in stackedNotes"
|
v-for="(stackedNote, index) in stackedNotes"
|
||||||
:key="stackedNote"
|
:key="stackedNote"
|
||||||
:index="index"
|
:index="index"
|
||||||
:user="user"
|
|
||||||
:repo="repo"
|
|
||||||
:sha="stackedNote"
|
:sha="stackedNote"
|
||||||
:title="titles[stackedNote ?? '']"
|
:title="titles[stackedNote ?? '']"
|
||||||
/>
|
/>
|
||||||
@@ -38,7 +36,6 @@ import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
|||||||
import {
|
import {
|
||||||
defineComponent,
|
defineComponent,
|
||||||
defineAsyncComponent,
|
defineAsyncComponent,
|
||||||
toRefs,
|
|
||||||
computed,
|
computed,
|
||||||
watch,
|
watch,
|
||||||
nextTick,
|
nextTick,
|
||||||
@@ -48,6 +45,7 @@ import HeaderNote from '@/components/HeaderNote.vue'
|
|||||||
import { useNote } from '@/hooks/useNote.hook'
|
import { useNote } from '@/hooks/useNote.hook'
|
||||||
import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
||||||
import { useLinks } from '@/hooks/useLinks.hook'
|
import { useLinks } from '@/hooks/useLinks.hook'
|
||||||
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
|
|
||||||
const StackedNote = defineAsyncComponent(() =>
|
const StackedNote = defineAsyncComponent(() =>
|
||||||
import('@/components/StackedNote.vue')
|
import('@/components/StackedNote.vue')
|
||||||
@@ -65,27 +63,31 @@ export default defineComponent({
|
|||||||
content: { type: String, required: false, default: null }
|
content: { type: String, required: false, default: null }
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
|
const store = useUserRepoStore()
|
||||||
const { renderString } = useMarkdown()
|
const { renderString } = useMarkdown()
|
||||||
const refProps = toRefs(props)
|
|
||||||
const { listenToClick } = useLinks('note-display')
|
const { listenToClick } = useLinks('note-display')
|
||||||
const { stackedNotes, resetStackedNotes } = useQueryStackedNotes()
|
const { stackedNotes, resetStackedNotes } = useQueryStackedNotes()
|
||||||
|
|
||||||
const { readme, ...noteProps } = useNote(
|
const { ...noteProps } = useNote('note-container')
|
||||||
'note-container',
|
|
||||||
refProps.user,
|
|
||||||
refProps.repo
|
|
||||||
)
|
|
||||||
|
|
||||||
const renderedContent = computed(() =>
|
const renderedContent = computed(() =>
|
||||||
props.content !== null ? renderString(props.content) : readme.value
|
props.content !== null ? renderString(props.content) : store.readme
|
||||||
)
|
)
|
||||||
|
|
||||||
const hasContent = computed(() => !!renderedContent.value)
|
const hasContent = computed(() => !!renderedContent.value)
|
||||||
|
|
||||||
watch(renderedContent, () => nextTick(() => listenToClick()))
|
watch(renderedContent, () =>
|
||||||
|
nextTick(() => {
|
||||||
|
console.log(renderedContent)
|
||||||
|
|
||||||
|
listenToClick()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
store.setUserRepo(props.user, props.repo)
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
readme.value = ''
|
store.resetUserRepo()
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, defineComponent, nextTick, toRefs, watch } from 'vue'
|
import { computed, defineComponent, nextTick, watch } from 'vue'
|
||||||
import { useFile } from '@/hooks/useFile.hook'
|
import { useFile } from '@/hooks/useFile.hook'
|
||||||
import { useLinks } from '@/hooks/useLinks.hook'
|
import { useLinks } from '@/hooks/useLinks.hook'
|
||||||
import { useNoteOverlay } from '@/hooks/useNoteOverlay.hook'
|
import { useNoteOverlay } from '@/hooks/useNoteOverlay.hook'
|
||||||
@@ -28,15 +28,12 @@ export default defineComponent({
|
|||||||
name: 'StackedNote',
|
name: 'StackedNote',
|
||||||
props: {
|
props: {
|
||||||
index: { type: Number, required: true },
|
index: { type: Number, required: true },
|
||||||
user: { type: String, required: true },
|
|
||||||
repo: { type: String, required: true },
|
|
||||||
title: { type: String, required: true },
|
title: { type: String, required: true },
|
||||||
sha: { type: String, required: true }
|
sha: { type: String, required: true }
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const refProps = toRefs(props)
|
|
||||||
const { scrollToFocusedNote } = useFocus()
|
const { scrollToFocusedNote } = useFocus()
|
||||||
const { content, fromCache } = useFile(props.user, props.repo, props.sha)
|
const { content, fromCache } = useFile(props.sha)
|
||||||
const { listenToClick } = useLinks('stacked-note', props.sha)
|
const { listenToClick } = useLinks('stacked-note', props.sha)
|
||||||
const className = computed(() => `stacked-note-${props.index}`)
|
const className = computed(() => `stacked-note-${props.index}`)
|
||||||
const titleClassName = computed(() => `title-${className.value}`)
|
const titleClassName = computed(() => `title-${className.value}`)
|
||||||
@@ -47,7 +44,7 @@ export default defineComponent({
|
|||||||
if (content.value) {
|
if (content.value) {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
listenToClick()
|
listenToClick()
|
||||||
useImages(refProps.user, refProps.repo, props.sha)
|
useImages(props.sha)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,13 +3,10 @@ import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
|||||||
import { useGitHubLogin } from '@/hooks/useGitHubLogin.hook'
|
import { useGitHubLogin } from '@/hooks/useGitHubLogin.hook'
|
||||||
import { Octokit } from '@octokit/rest'
|
import { Octokit } from '@octokit/rest'
|
||||||
import { useNoteCache } from '@/modules/note/hooks/useNoteCache'
|
import { useNoteCache } from '@/modules/note/hooks/useNoteCache'
|
||||||
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
|
|
||||||
export const useFile = (
|
export const useFile = (sha: string, retrieveContent = true) => {
|
||||||
owner: string,
|
const store = useUserRepoStore()
|
||||||
repo: string,
|
|
||||||
sha: string,
|
|
||||||
retrieveContent = true
|
|
||||||
) => {
|
|
||||||
const { getCachedNote, saveCacheNote } = useNoteCache(sha)
|
const { getCachedNote, saveCacheNote } = useNoteCache(sha)
|
||||||
const { accessToken } = useGitHubLogin()
|
const { accessToken } = useGitHubLogin()
|
||||||
const fromCache = ref(false)
|
const fromCache = ref(false)
|
||||||
@@ -21,16 +18,20 @@ export const useFile = (
|
|||||||
const content = ref('')
|
const content = ref('')
|
||||||
|
|
||||||
const getFileContent = async () => {
|
const getFileContent = async () => {
|
||||||
|
if (!store.user || !store.repo) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
const file = await octokit.request(
|
const file = await octokit.request(
|
||||||
'GET /repos/{owner}/{repo}/git/blobs/{file_sha}',
|
'GET /repos/{owner}/{repo}/git/blobs/{file_sha}',
|
||||||
{
|
{
|
||||||
owner,
|
owner: store.user,
|
||||||
repo,
|
repo: store.repo,
|
||||||
file_sha: sha
|
file_sha: sha
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return file?.data.content
|
return file?.data.content ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
const getContent = async () => {
|
const getContent = async () => {
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
import { useFile } from '@/hooks/useFile.hook'
|
import { useFile } from '@/hooks/useFile.hook'
|
||||||
import { useRepo } from '@/hooks/useRepo.hook'
|
|
||||||
import { resolvePath } from '@/modules/repo/services/resolvePath'
|
import { resolvePath } from '@/modules/repo/services/resolvePath'
|
||||||
import { computed, Ref } from 'vue'
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
const SRC_PREFIX = 'data:image/jpeg;charset=utf-8;base64,'
|
const SRC_PREFIX = 'data:image/jpeg;charset=utf-8;base64,'
|
||||||
|
|
||||||
export const useImages = (
|
export const useImages = (sha: string) => {
|
||||||
user: Ref<string>,
|
const store = useUserRepoStore()
|
||||||
repo: Ref<string>,
|
|
||||||
sha: string
|
|
||||||
) => {
|
|
||||||
const { tree } = useRepo(user, repo, false)
|
|
||||||
|
|
||||||
const currentFilePath = computed(
|
const currentFilePath = computed(
|
||||||
() => tree.value.find((file) => file.sha === sha)?.path
|
() => store.files.find((file) => file.sha === sha)?.path
|
||||||
)
|
)
|
||||||
|
|
||||||
const images = document.querySelectorAll(`.note-${sha} img`)
|
const images = document.querySelectorAll(`.note-${sha} img`)
|
||||||
@@ -30,17 +26,12 @@ export const useImages = (
|
|||||||
image.getAttribute('src') ?? ''
|
image.getAttribute('src') ?? ''
|
||||||
)
|
)
|
||||||
|
|
||||||
const imageFile = tree.value.find((file) => file.path === imageFilePath)
|
const imageFile = store.files.find((file) => file.path === imageFilePath)
|
||||||
|
|
||||||
if (!imageFile?.sha) {
|
if (!imageFile?.sha) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const { getFileContent } = useFile(
|
const { getFileContent } = useFile(imageFile.sha, false)
|
||||||
user.value,
|
|
||||||
repo.value,
|
|
||||||
imageFile.sha,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
|
|
||||||
const fileContent = await getFileContent()
|
const fileContent = await getFileContent()
|
||||||
image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`)
|
image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`)
|
||||||
|
|||||||
@@ -1,40 +1,27 @@
|
|||||||
import {
|
import { computed, onMounted, onUnmounted, watch } from '@vue/runtime-core'
|
||||||
computed,
|
|
||||||
nextTick,
|
|
||||||
onMounted,
|
|
||||||
onUnmounted,
|
|
||||||
watch
|
|
||||||
} from '@vue/runtime-core'
|
|
||||||
|
|
||||||
import { NOTE_WIDTH } from '@/constants/note-width'
|
import { NOTE_WIDTH } from '@/constants/note-width'
|
||||||
import { Ref } from '@vue/reactivity'
|
|
||||||
import { noteEventBus } from '@/bus/noteBusEvent'
|
import { noteEventBus } from '@/bus/noteBusEvent'
|
||||||
import { useFocus } from '@/hooks/useFocus.hook'
|
import { useFocus } from '@/hooks/useFocus.hook'
|
||||||
import { useLinks } from '@/hooks/useLinks.hook'
|
|
||||||
import { useOverlay } from '@/hooks/useOverlay.hook'
|
import { useOverlay } from '@/hooks/useOverlay.hook'
|
||||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
||||||
import { useRepo } from '@/hooks/useRepo.hook'
|
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { resolvePath } from '@/modules/repo/services/resolvePath'
|
import { resolvePath } from '@/modules/repo/services/resolvePath'
|
||||||
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
|
|
||||||
export const useNote = (
|
export const useNote = (containerClass: string) => {
|
||||||
containerClass: string,
|
const store = useUserRepoStore()
|
||||||
user: Ref<string>,
|
|
||||||
repo: Ref<string>
|
|
||||||
) => {
|
|
||||||
const { push, currentRoute } = useRouter()
|
const { push, currentRoute } = useRouter()
|
||||||
const { isMobile } = useOverlay(false)
|
const { isMobile } = useOverlay(false)
|
||||||
const { scrollToFocusedNote } = useFocus()
|
const { scrollToFocusedNote } = useFocus()
|
||||||
const { stackedNotes, updateQueryStackedNotes } = useQueryStackedNotes()
|
const { stackedNotes, updateQueryStackedNotes } = useQueryStackedNotes()
|
||||||
const { readme, notFound, tree } = useRepo(user, repo)
|
|
||||||
const { listenToClick } = useLinks('note-display')
|
|
||||||
|
|
||||||
const titles = computed(() =>
|
const titles = computed(() =>
|
||||||
stackedNotes.value?.reduce((obj: Record<string, string>, note) => {
|
stackedNotes.value?.reduce((obj: Record<string, string>, note) => {
|
||||||
if (!note) {
|
if (!note) {
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
const filePath = tree.value.find((file) => file.sha === note)?.path ?? ''
|
const filePath = store.files.find((file) => file.sha === note)?.path ?? ''
|
||||||
|
|
||||||
const fileNames = filePath.split('.')
|
const fileNames = filePath.split('.')
|
||||||
|
|
||||||
@@ -52,11 +39,13 @@ export const useNote = (
|
|||||||
|
|
||||||
const unsubscribeLink = noteEventBus.addEventBusListener(
|
const unsubscribeLink = noteEventBus.addEventBusListener(
|
||||||
({ path, currentNoteSHA }) => {
|
({ path, currentNoteSHA }) => {
|
||||||
const currentFile = tree.value.find((file) => file.sha === currentNoteSHA)
|
const currentFile = store.files.find(
|
||||||
|
(file) => file.sha === currentNoteSHA
|
||||||
|
)
|
||||||
|
|
||||||
const finalPath = resolvePath(currentFile?.path ?? '', path)
|
const finalPath = resolvePath(currentFile?.path ?? '', path)
|
||||||
|
|
||||||
const file = tree.value.find((file) => file.path === finalPath)
|
const file = store.files.find((file) => file.path === finalPath)
|
||||||
|
|
||||||
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
|
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
|
||||||
scrollToFocusedNote(file?.sha)
|
scrollToFocusedNote(file?.sha)
|
||||||
@@ -88,8 +77,8 @@ export const useNote = (
|
|||||||
push({
|
push({
|
||||||
name: currentRoute.value.name ?? 'Home',
|
name: currentRoute.value.name ?? 'Home',
|
||||||
params: {
|
params: {
|
||||||
user: user.value,
|
user: store.user,
|
||||||
repo: repo.value
|
repo: store.repo
|
||||||
},
|
},
|
||||||
query: {
|
query: {
|
||||||
stackedNotes: newStackedNotes
|
stackedNotes: newStackedNotes
|
||||||
@@ -101,12 +90,6 @@ export const useNote = (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
watch([readme, user, repo], () => {
|
|
||||||
nextTick(() => {
|
|
||||||
listenToClick()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const resizeContainer = () => {
|
const resizeContainer = () => {
|
||||||
const element = document.querySelector(
|
const element = document.querySelector(
|
||||||
`.${containerClass}`
|
`.${containerClass}`
|
||||||
@@ -134,8 +117,6 @@ export const useNote = (
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
titles,
|
titles
|
||||||
readme,
|
|
||||||
notFound
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,104 +0,0 @@
|
|||||||
import { Ref, ref, watch } from '@vue/runtime-core'
|
|
||||||
|
|
||||||
import { Octokit } from '@octokit/rest'
|
|
||||||
import { useGitHubLogin } from '@/hooks/useGitHubLogin.hook'
|
|
||||||
import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
|
||||||
import { useNoteCache } from '@/modules/note/hooks/useNoteCache'
|
|
||||||
|
|
||||||
interface Tree {
|
|
||||||
path?: string
|
|
||||||
mode?: string
|
|
||||||
type?: string
|
|
||||||
sha?: string
|
|
||||||
size?: number
|
|
||||||
url?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const tree = ref<Tree[]>([])
|
|
||||||
|
|
||||||
export const useRepo = (
|
|
||||||
owner: Ref<string>,
|
|
||||||
repo: Ref<string>,
|
|
||||||
retrieve = true,
|
|
||||||
retrieveReadme = true
|
|
||||||
) => {
|
|
||||||
const { getCachedNote, saveCacheNote } = useNoteCache('README')
|
|
||||||
const { accessToken } = useGitHubLogin()
|
|
||||||
const { render } = useMarkdown()
|
|
||||||
|
|
||||||
const octokit = new Octokit({
|
|
||||||
auth: accessToken.value
|
|
||||||
})
|
|
||||||
|
|
||||||
const readme = ref<string | null>(null)
|
|
||||||
const notFound = ref(false)
|
|
||||||
|
|
||||||
const retrieveRepo = async () => {
|
|
||||||
if (!owner.value || !repo.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const cachedReadme = await getCachedNote()
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (retrieveReadme) {
|
|
||||||
if (cachedReadme) {
|
|
||||||
readme.value = render(cachedReadme.content)
|
|
||||||
}
|
|
||||||
|
|
||||||
const README = await octokit.repos.getReadme({
|
|
||||||
owner: owner.value,
|
|
||||||
repo: repo.value
|
|
||||||
})
|
|
||||||
|
|
||||||
if (README) {
|
|
||||||
readme.value = render(README.data.content)
|
|
||||||
saveCacheNote(README.data.content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const commits = await octokit.request(
|
|
||||||
'GET /repos/{owner}/{repo}/commits',
|
|
||||||
{
|
|
||||||
repo: repo.value,
|
|
||||||
owner: owner.value
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const lastCommit = commits.data.shift()
|
|
||||||
|
|
||||||
if (!lastCommit) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const treeResponse = await octokit.request(
|
|
||||||
'GET /repos/{owner}/{repo}/git/trees/{tree_sha}',
|
|
||||||
{
|
|
||||||
repo: repo.value,
|
|
||||||
owner: owner.value,
|
|
||||||
tree_sha: lastCommit.commit.tree.sha,
|
|
||||||
recursive: 'true'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (treeResponse) {
|
|
||||||
tree.value = treeResponse.data.tree.filter((t) => t.type === 'blob')
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (!cachedReadme) {
|
|
||||||
notFound.value = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retrieve) {
|
|
||||||
retrieveRepo()
|
|
||||||
}
|
|
||||||
|
|
||||||
watch([owner, repo], () => retrieveRepo())
|
|
||||||
|
|
||||||
return {
|
|
||||||
readme,
|
|
||||||
notFound,
|
|
||||||
tree
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import '@/registerServiceWorker'
|
import '@/registerServiceWorker'
|
||||||
|
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import { createI18n } from 'vue-i18n'
|
import { createI18n } from 'vue-i18n'
|
||||||
@@ -14,4 +15,5 @@ const i18n = createI18n({
|
|||||||
createApp(App)
|
createApp(App)
|
||||||
.use(router)
|
.use(router)
|
||||||
.use(i18n)
|
.use(i18n)
|
||||||
|
.use(createPinia())
|
||||||
.mount('#app')
|
.mount('#app')
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
import { useRepo } from '@/hooks/useRepo.hook'
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
import { computed, Ref } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
|
||||||
export const useFolderNotes = (
|
export const useFolderNotes = (folder: string) => {
|
||||||
folder: string,
|
const store = useUserRepoStore()
|
||||||
owner: Ref<string>,
|
|
||||||
repo: Ref<string>
|
|
||||||
) => {
|
|
||||||
const { tree } = useRepo(owner, repo, true, false)
|
|
||||||
|
|
||||||
const fleetingNotes = computed(() =>
|
const fleetingNotes = computed(() =>
|
||||||
tree.value.filter(
|
store.files.filter(
|
||||||
(file) => file.path?.startsWith(folder) && file.path?.endsWith('.md')
|
(file) => file.path?.startsWith(folder) && file.path?.endsWith('.md')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
const content = computed(() =>
|
const content = computed(() =>
|
||||||
fleetingNotes.value.length
|
fleetingNotes.value?.length
|
||||||
? fleetingNotes.value
|
? fleetingNotes.value
|
||||||
.map((note) => `- [${note.path}](${note.path})`)
|
.map((note) => `- [${note.path}](${note.path})`)
|
||||||
.join('\n')
|
.join('\n')
|
||||||
|
|||||||
8
src/modules/repo/interfaces/RepoFile.ts
Normal file
8
src/modules/repo/interfaces/RepoFile.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export interface RepoFile {
|
||||||
|
path?: string
|
||||||
|
mode?: string
|
||||||
|
type?: string
|
||||||
|
sha?: string
|
||||||
|
size?: number
|
||||||
|
url?: string
|
||||||
|
}
|
||||||
77
src/modules/repo/services/repo.ts
Normal file
77
src/modules/repo/services/repo.ts
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import { useGitHubLogin } from '@/hooks/useGitHubLogin.hook'
|
||||||
|
import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
||||||
|
import { useNoteCache } from '@/modules/note/hooks/useNoteCache'
|
||||||
|
import { RepoFile } from '@/modules/repo/interfaces/RepoFile'
|
||||||
|
import { Octokit } from '@octokit/rest'
|
||||||
|
|
||||||
|
export const getFiles = async (
|
||||||
|
owner: string,
|
||||||
|
repo: string
|
||||||
|
): Promise<RepoFile[]> => {
|
||||||
|
if (!owner || !repo) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const { accessToken } = useGitHubLogin()
|
||||||
|
|
||||||
|
const octokit = new Octokit({
|
||||||
|
auth: accessToken.value
|
||||||
|
})
|
||||||
|
|
||||||
|
const commits = await octokit.request('GET /repos/{owner}/{repo}/commits', {
|
||||||
|
owner,
|
||||||
|
repo
|
||||||
|
})
|
||||||
|
|
||||||
|
const lastCommit = commits.data.shift()
|
||||||
|
|
||||||
|
if (!lastCommit) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const treeResponse = await octokit.request(
|
||||||
|
'GET /repos/{owner}/{repo}/git/trees/{tree_sha}',
|
||||||
|
{
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
tree_sha: lastCommit.commit.tree.sha,
|
||||||
|
recursive: 'true'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return treeResponse?.data.tree.filter((t) => t.type === 'blob') ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getMainReadme = async (owner: string, repo: string) => {
|
||||||
|
if (!owner || !repo) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const { render } = useMarkdown()
|
||||||
|
const { getCachedNote, saveCacheNote } = useNoteCache('README')
|
||||||
|
|
||||||
|
const cachedReadme = await getCachedNote()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { accessToken } = useGitHubLogin()
|
||||||
|
const octokit = new Octokit({
|
||||||
|
auth: accessToken.value
|
||||||
|
})
|
||||||
|
|
||||||
|
const README = await octokit.repos.getReadme({
|
||||||
|
owner,
|
||||||
|
repo
|
||||||
|
})
|
||||||
|
|
||||||
|
if (README) {
|
||||||
|
saveCacheNote(README.data.content)
|
||||||
|
return render(README.data.content)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(error)
|
||||||
|
if (cachedReadme) {
|
||||||
|
return render(cachedReadme.content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
39
src/modules/repo/store/userRepo.store.ts
Normal file
39
src/modules/repo/store/userRepo.store.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { RepoFile } from '@/modules/repo/interfaces/RepoFile'
|
||||||
|
import { getFiles, getMainReadme } from '@/modules/repo/services/repo'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
user: string
|
||||||
|
repo: string
|
||||||
|
files: RepoFile[]
|
||||||
|
readme: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useUserRepoStore = defineStore({
|
||||||
|
id: 'USER_REPO_STATE',
|
||||||
|
state: (): State => ({
|
||||||
|
user: '',
|
||||||
|
repo: '',
|
||||||
|
files: [],
|
||||||
|
readme: null
|
||||||
|
}),
|
||||||
|
actions: {
|
||||||
|
async setUserRepo(newUser: string, newRepo: string) {
|
||||||
|
this.user = newUser
|
||||||
|
this.repo = newRepo
|
||||||
|
const [readme, files] = await Promise.all([
|
||||||
|
getMainReadme(newUser, newRepo),
|
||||||
|
getFiles(newUser, newRepo)
|
||||||
|
])
|
||||||
|
|
||||||
|
this.readme = readme
|
||||||
|
this.files = files
|
||||||
|
},
|
||||||
|
resetUserRepo() {
|
||||||
|
this.user = ''
|
||||||
|
this.repo = ''
|
||||||
|
this.files = []
|
||||||
|
this.readme = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
1
src/modules/user/hooks/useUserSettings.ts
Normal file
1
src/modules/user/hooks/useUserSettings.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const useUserSettings = () => {}
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
@charset "utf-8";
|
@charset "utf-8";
|
||||||
@import url('https://fonts.googleapis.com/css2?family=Courier+Prime&display=swap');
|
@import url('https://fonts.googleapis.com/css2?family=Courgette&family=IBM+Plex+Serif&family=Kiwi+Maru&family=Maven+Pro&family=Noto+Sans+KR&family=Tajawal&display=swap');
|
||||||
|
|
||||||
|
/**
|
||||||
|
font-family: 'Courgette', cursive;
|
||||||
|
font-family: 'IBM Plex Serif', serif;
|
||||||
|
font-family: 'Kiwi Maru', serif;
|
||||||
|
font-family: 'Maven Pro', sans-serif;
|
||||||
|
font-family: 'Noto Sans KR', sans-serif;
|
||||||
|
font-family: 'Tajawal', sans-serif;
|
||||||
|
*/
|
||||||
|
|
||||||
$primary: #2c3a47;
|
$primary: #2c3a47;
|
||||||
$link: #3b7e70;
|
$link: #3b7e70;
|
||||||
|
|||||||
@@ -9,9 +9,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
|
||||||
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
|
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
|
||||||
import { defineAsyncComponent, defineComponent, onMounted, toRefs } from 'vue'
|
import { defineAsyncComponent, defineComponent } from 'vue'
|
||||||
|
|
||||||
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
|
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
|
||||||
|
|
||||||
@@ -26,18 +25,8 @@ export default defineComponent({
|
|||||||
user: { type: String, required: true },
|
user: { type: String, required: true },
|
||||||
repo: { type: String, required: true }
|
repo: { type: String, required: true }
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup() {
|
||||||
const refProps = toRefs(props)
|
const { content } = useFolderNotes(DRAFT_FOLDER)
|
||||||
const { content } = useFolderNotes(
|
|
||||||
DRAFT_FOLDER,
|
|
||||||
refProps.user,
|
|
||||||
refProps.repo
|
|
||||||
)
|
|
||||||
const { resetStackedNotes } = useQueryStackedNotes()
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
resetStackedNotes()
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content
|
content
|
||||||
|
|||||||
@@ -14,9 +14,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
|
||||||
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
|
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
|
||||||
import { defineAsyncComponent, defineComponent, onMounted, toRefs } from 'vue'
|
import { defineAsyncComponent, defineComponent } from 'vue'
|
||||||
|
|
||||||
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
|
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
|
||||||
|
|
||||||
@@ -31,18 +30,8 @@ export default defineComponent({
|
|||||||
user: { type: String, required: true },
|
user: { type: String, required: true },
|
||||||
repo: { type: String, required: true }
|
repo: { type: String, required: true }
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup() {
|
||||||
const refProps = toRefs(props)
|
const { content } = useFolderNotes(FLEETING_NOTES_FOLDER)
|
||||||
const { content } = useFolderNotes(
|
|
||||||
FLEETING_NOTES_FOLDER,
|
|
||||||
refProps.user,
|
|
||||||
refProps.repo
|
|
||||||
)
|
|
||||||
const { resetStackedNotes } = useQueryStackedNotes()
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
resetStackedNotes()
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content
|
content
|
||||||
|
|||||||
@@ -6,13 +6,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import { defineComponent, defineAsyncComponent, computed } from 'vue'
|
||||||
defineComponent,
|
|
||||||
defineAsyncComponent,
|
|
||||||
computed,
|
|
||||||
toRefs,
|
|
||||||
watch
|
|
||||||
} from 'vue'
|
|
||||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
||||||
|
|
||||||
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
|
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
|
||||||
@@ -32,13 +26,8 @@ export default defineComponent({
|
|||||||
repo: { type: String, required: false, default: '' }
|
repo: { type: String, required: false, default: '' }
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const refProps = toRefs(props)
|
|
||||||
const { resetStackedNotes } = useQueryStackedNotes()
|
const { resetStackedNotes } = useQueryStackedNotes()
|
||||||
|
|
||||||
watch([refProps.user, refProps.repo], () => {
|
|
||||||
resetStackedNotes()
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
resetStackedNotes,
|
resetStackedNotes,
|
||||||
routeKey: computed(() => `${props.user}-${props.repo}`)
|
routeKey: computed(() => `${props.user}-${props.repo}`)
|
||||||
|
|||||||
@@ -8886,6 +8886,11 @@ pify@^4.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231"
|
resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231"
|
||||||
integrity sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==
|
integrity sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==
|
||||||
|
|
||||||
|
pinia@^2.0.0-alpha.7:
|
||||||
|
version "2.0.0-alpha.7"
|
||||||
|
resolved "https://registry.yarnpkg.com/pinia/-/pinia-2.0.0-alpha.7.tgz#3b55af0185a45e6e1a75ba90f6da3e1a61623767"
|
||||||
|
integrity sha512-IXPG+4elwC+0h5r3FZUhcH+XwywMN+f9uxoMxzapz5ywBfo7BeE48wpC1o+81qnil5m3FhBOjMKZeS7t0t6ljw==
|
||||||
|
|
||||||
pinkie-promise@^2.0.0:
|
pinkie-promise@^2.0.0:
|
||||||
version "2.0.1"
|
version "2.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa"
|
resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa"
|
||||||
|
|||||||
Reference in New Issue
Block a user