File tree Expand file tree Collapse file tree 5 files changed +17
-5
lines changed Expand file tree Collapse file tree 5 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,13 @@ import NProgress from "nprogress"
44import { useRouter , usePathname } from "next/navigation"
55import { useContext } from "react"
66import { ProjectsContext } from "@/common"
7- import { Project , ProjectNavigator , getProjectSelectionFromPath } from "../domain"
7+ import {
8+ Project ,
9+ ProjectNavigator ,
10+ getProjectSelectionFromPath ,
11+ getDefaultSpecification
12+
13+ } from "../domain"
814
915export default function useProjectSelection ( ) {
1016 const router = useRouter ( )
@@ -29,7 +35,7 @@ export default function useProjectSelection() {
2935 } ,
3036 selectProject : ( project : Project ) => {
3137 const version = project . versions [ 0 ]
32- const specification = version . specifications . find ( spec => spec . isDefault ) || version . specifications [ 0 ]
38+ const specification = getDefaultSpecification ( version )
3339 NProgress . start ( )
3440 projectNavigator . navigate (
3541 project . owner ,
Original file line number Diff line number Diff line change 11import Project from "./Project"
2+ import { getDefaultSpecification } from "./Version"
23
34interface IPathnameReader {
45 readonly pathname : string
@@ -36,7 +37,7 @@ export default class ProjectNavigator {
3637 if ( candidateSpecification ) {
3738 this . router . push ( `/${ project . owner } /${ project . name } /${ newVersion . id } /${ candidateSpecification . id } ` )
3839 } else {
39- const defaultOrFirstSpecification = newVersion . specifications . find ( spec => spec . isDefault ) || newVersion . specifications [ 0 ]
40+ const defaultOrFirstSpecification = getDefaultSpecification ( newVersion )
4041 this . router . push ( `/${ project . owner } /${ project . name } /${ newVersion . id } /${ defaultOrFirstSpecification . id } ` )
4142 }
4243 }
Original file line number Diff line number Diff line change @@ -12,3 +12,7 @@ export const VersionSchema = z.object({
1212type Version = z . infer < typeof VersionSchema >
1313
1414export default Version
15+
16+ export function getDefaultSpecification ( version : Version ) {
17+ return version . specifications . find ( ( spec ) => spec . isDefault ) || version . specifications [ 0 ]
18+ }
Original file line number Diff line number Diff line change 11import Project from "./Project"
2- import Version from "./Version"
2+ import Version , { getDefaultSpecification } from "./Version"
33import OpenApiSpecification from "./OpenApiSpecification"
44
55export default function getProjectSelectionFromPath ( {
@@ -61,7 +61,7 @@ export default function getProjectSelectionFromPath({
6161 if ( specificationId && ! didMoveSpecificationIdToVersionId ) {
6262 specification = version . specifications . find ( e => e . id == specificationId )
6363 } else if ( version . specifications . length > 0 ) {
64- specification = version . specifications . find ( spec => spec . isDefault ) || version . specifications [ 0 ]
64+ specification = getDefaultSpecification ( version )
6565 }
6666 return { project, version, specification }
6767}
Original file line number Diff line number Diff line change @@ -16,3 +16,4 @@ export { default as ProjectNavigator } from "./ProjectNavigator"
1616export { default as ProjectRepository } from "./ProjectRepository"
1717export { default as updateWindowTitle } from "./updateWindowTitle"
1818export type { default as Version } from "./Version"
19+ export { getDefaultSpecification } from "./Version"
You can’t perform that action at this time.
0 commit comments