Skip to content

Commit

Permalink
Fix commit loading
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed Apr 17, 2024
1 parent 44e96ff commit 4114479
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
5 changes: 4 additions & 1 deletion dashboard/src/pages/builds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const builds: Component = () => {
.then((res) => res.builds),
)
const hashes = () => builds()?.map((b) => b.commit)
const [commits] = createResource(() => getRepositoryCommits(hashes() || []))
const [commits] = createResource(
() => hashes(),
(hashes) => getRepositoryCommits(hashes),
)

const sortedBuilds = createMemo(
() =>
Expand Down
8 changes: 1 addition & 7 deletions dashboard/src/pages/repos/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ const MainView = styled('div', {
})

export default () => {
const { repo, apps, hasPermission } = useRepositoryData()
const { repo, apps, commits, hasPermission } = useRepositoryData()
const loaded = () => !!(repo() && apps())

const hashes = () => apps()?.map((app) => app.commit)
const [commits] = createResource(
() => hashes(),
(hashes) => getRepositoryCommits(hashes),
)

const navigator = useNavigate()
const showPlaceHolder = createMemo(() => apps()?.length === 0)

Expand Down
21 changes: 16 additions & 5 deletions dashboard/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
revalidateBuilds,
revalidateRepository,
} from './libs/api'
import app from '/@/App'

const loadApplicationData: RouteLoadFunc = ({ params }) => {
getApplication(params.id).then((app) => {
Expand All @@ -37,14 +38,18 @@ export const useApplicationData = () => {
const repo = createAsync(async () => app() && (await getRepository(app()?.repositoryId)))
const builds = createAsync(() => getBuilds(params.id))
const hashes = () => {
const h: string[] = []
const a = app()
if (a) h.push(a.commit)
const b = builds()
if (b) h.push(...b.map((b) => b.commit))
return h
if (a && b) return [a.commit, ...b.map((b) => b.commit)]
return undefined
}
const commits = createAsync(async () => getRepositoryCommits(hashes()))
const commits = createAsync(
async () => {
const h = hashes()
if (!h) return undefined
return getRepositoryCommits(h)
},
)
const refetch = async () => {
await Promise.all([revalidateApplication(params.id), revalidateBuilds(params.id)])
}
Expand All @@ -71,11 +76,17 @@ export const useRepositoryData = () => {
const params = useParams()
const repo = createAsync(() => getRepository(params.id))
const apps = createAsync(() => getRepositoryApps(params.id))
const commits = createAsync(async () => {
const a = apps()
if (!a) return undefined
return getRepositoryCommits(a.map((a) => a.commit))
})
const refetchRepo = () => revalidateRepository(params.id)
const hasPermission = createMemo(() => hasRepositoryPermission(repo))
return {
repo,
apps,
commits,
refetchRepo,
hasPermission,
}
Expand Down

0 comments on commit 4114479

Please sign in to comment.