Skip to content

Commit

Permalink
fix: forkStatus should not run if repo is not a fork
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasBuchfink committed Apr 10, 2024
1 parent 8b077ca commit bcfbe26
Showing 1 changed file with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,31 +312,6 @@ export function EditorStateProvider(props: { children: JSXElement }) {
}
)

const isForkSyncDisabled = () =>
localStorage.disableForkSyncWarning?.some(
(repo) => repo.owner === routeParams().owner && repo.repository === routeParams().repository
)

const [forkStatus, { refetch: refetchForkStatus, mutate: mutateForkStatus }] = createResource(
() => {
if (repo() && !isForkSyncDisabled()) {
return { repo: repo() }
} else {
return false
}
},
async (args) => {
const value = await args.repo!.forkStatus()
if ("error" in value) {
setLixErrors([new Error(value.error), ...lixErrors()])
return { ahead: 0, behind: 0, conflicts: false }
} else {
return value
}
},
{ initialValue: { ahead: 0, behind: 0, conflicts: false } }
)

async function pushChanges(args: {
user: LocalStorageSchema["user"]
setFsChange: (date: Date) => void
Expand Down Expand Up @@ -551,6 +526,32 @@ export function EditorStateProvider(props: { children: JSXElement }) {
}
)

const isForkSyncDisabled = () =>
localStorage.disableForkSyncWarning?.some(
(repo) => repo.owner === routeParams().owner && repo.repository === routeParams().repository
)

const [forkStatus, { refetch: refetchForkStatus, mutate: mutateForkStatus }] = createResource(
() => {
const repoMeta = githubRepositoryInformation()
if (repo() && !isForkSyncDisabled() && repoMeta && !("error" in repoMeta) && repoMeta.isFork) {
return { repo: repo() }
} else {
return false
}
},
async (args) => {
const value = await args.repo!.forkStatus()
if ("error" in value) {
setLixErrors([new Error(value.error), ...lixErrors()])
return { ahead: 0, behind: 0, conflicts: false }
} else {
return value
}
},
{ initialValue: { ahead: 0, behind: 0, conflicts: false } }
)

const [previousLoginStatus, setPreviousLoginStatus] = createSignal(localStorage?.user?.isLoggedIn)
createEffect(
on(
Expand Down

0 comments on commit bcfbe26

Please sign in to comment.