-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update src-dest UI in Pulls list * Show closed/merged timestamp in the Pulls list * Show merged commit link in merged PR details * Cleanup * Handle empty diffs * Handle deleted branch errors * Disable button when branch not found * Update field name * Fix PR comments
- Loading branch information
Showing
5 changed files
with
241 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { createContext, useReducer } from "react"; | ||
|
||
type DiffContextType = { | ||
results: object[] | null; | ||
loading: boolean; | ||
error: string | null; | ||
nextPage: object | null; | ||
}; | ||
|
||
enum DiffActionType { | ||
setResults = 'setResults', | ||
} | ||
|
||
interface Action { | ||
type: DiffActionType; | ||
value: DiffContextType; | ||
} | ||
|
||
const initialDiffContext: DiffContextType = { | ||
results: [], | ||
loading: false, | ||
error: null, | ||
nextPage: null, | ||
}; | ||
|
||
const diffContextReducer = (state: DiffContextType, action: Action) => { | ||
switch (action.type) { | ||
case DiffActionType.setResults: | ||
return {...state, ...action.value}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
type ContextType = { | ||
state: DiffContextType, | ||
dispatch: React.Dispatch<Action>, | ||
}; | ||
|
||
const DiffContext = createContext<ContextType>({ | ||
state: initialDiffContext, | ||
dispatch: () => null | ||
}); | ||
|
||
// @ts-expect-error - it doesn't like the "children" prop | ||
const WithDiffContext: React.FC = ({children}) => { | ||
const [state, dispatch] = useReducer(diffContextReducer, initialDiffContext); | ||
|
||
return ( | ||
<DiffContext.Provider value={{state, dispatch}}> | ||
{children} | ||
</DiffContext.Provider> | ||
) | ||
} | ||
|
||
export { WithDiffContext, DiffContext, DiffActionType }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.