parent
02e1d29084
commit
9024f6e558
@ -0,0 +1,24 @@ |
||||
import React, { useContext } from 'react' |
||||
import { gitPluginContext } from '../gitui' |
||||
|
||||
interface ButtonWithContextProps { |
||||
onClick: React.MouseEventHandler<HTMLButtonElement>; |
||||
children: React.ReactNode; |
||||
disabledCondition?: boolean; // Optional additional disabling condition
|
||||
// You can add other props if needed, like 'type', 'className', etc.
|
||||
[key: string]: any; // Allow additional props to be passed
|
||||
} |
||||
|
||||
// This component extends a button, disabling it when loading is true
|
||||
const GitUIButton = ({children, disabledCondition = false, ...rest }:ButtonWithContextProps) => { |
||||
const { loading } = React.useContext(gitPluginContext) |
||||
|
||||
const isDisabled = loading || disabledCondition |
||||
return ( |
||||
<button disabled={loading} {...rest}> |
||||
{children} |
||||
</button> |
||||
); |
||||
}; |
||||
|
||||
export default GitUIButton; |
@ -1,16 +1,18 @@ |
||||
import React, { useEffect, useState } from "react"; |
||||
import { gitActionsContext } from "../../../state/context"; |
||||
import GitUIButton from "../../buttons/gituibutton"; |
||||
import { gitPluginContext } from "../../gitui"; |
||||
|
||||
|
||||
export const Fetch = () => { |
||||
const actions = React.useContext(gitActionsContext) |
||||
const fetch = async () => { |
||||
await actions.fetch() |
||||
} |
||||
|
||||
const context = React.useContext(gitPluginContext) |
||||
|
||||
return ( |
||||
<> |
||||
<button type="button" onClick={async () => fetch()} className="btn btn-primary w-100">Fetch</button> |
||||
<div className="btn-group w-100" role="group"> |
||||
<GitUIButton type="button" onClick={async () => actions.fetch()} className="btn btn-primary mr-1">Fetch {context.upstream}</GitUIButton> |
||||
<GitUIButton type="button" onClick={async () => actions.fetch(null, null, context.currentBranch.name, null, true )} className="btn btn-primary">Fetch {context.currentBranch.name}</GitUIButton> |
||||
</div> |
||||
</>) |
||||
} |
Loading…
Reference in new issue