mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
chore: status vs state
This commit is contained in:
parent
e9f7ee2f91
commit
69614104ec
4 changed files with 19 additions and 19 deletions
|
|
@ -10,13 +10,13 @@ const className = 'clippy-wrapper'
|
|||
export const ClippyClassName = className
|
||||
|
||||
export function Clippy({ codeSnippetElement }: Props) {
|
||||
const [status, setStatus] = React.useState<'normal' | 'success' | 'fail'>('normal')
|
||||
const [state, setState] = React.useState<'normal' | 'success' | 'fail'>('normal')
|
||||
React.useEffect(() => {
|
||||
const timer = window.setTimeout(() => {
|
||||
setStatus('normal')
|
||||
setState('normal')
|
||||
}, 1000)
|
||||
return () => window.clearTimeout(timer)
|
||||
}, [status])
|
||||
}, [state])
|
||||
|
||||
// Temporary fix:
|
||||
// React moved root node of event delegation since v17
|
||||
|
|
@ -26,7 +26,7 @@ export function Clippy({ codeSnippetElement }: Props) {
|
|||
const element = elementRef.current
|
||||
if (element) {
|
||||
function onClippyClick() {
|
||||
setStatus(copyElementContent(codeSnippetElement) ? 'success' : 'fail')
|
||||
setState(copyElementContent(codeSnippetElement) ? 'success' : 'fail')
|
||||
}
|
||||
element.addEventListener('click', onClippyClick)
|
||||
return () => element.removeEventListener('click', onClippyClick)
|
||||
|
|
@ -36,7 +36,7 @@ export function Clippy({ codeSnippetElement }: Props) {
|
|||
return (
|
||||
<div className={className}>
|
||||
<button className="clippy" ref={elementRef}>
|
||||
<i className={cx('icon', status)} />
|
||||
<i className={cx('icon', state)} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
|||
const {
|
||||
metaData,
|
||||
treeData,
|
||||
status,
|
||||
state,
|
||||
defer,
|
||||
error,
|
||||
shouldShow,
|
||||
|
|
@ -59,7 +59,7 @@ const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
|||
|
||||
React.useEffect(
|
||||
function attachKeyDown() {
|
||||
if (status === 'disabled' || !configContext.value.shortcut) return
|
||||
if (state === 'disabled' || !configContext.value.shortcut) return
|
||||
|
||||
function onKeyDown(e: KeyboardEvent) {
|
||||
const keys = keyHelper.parseEvent(e)
|
||||
|
|
@ -70,13 +70,13 @@ const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
|||
window.addEventListener('keydown', onKeyDown)
|
||||
return () => window.removeEventListener('keydown', onKeyDown)
|
||||
},
|
||||
[toggleShowSideBar, status === 'disabled', configContext.value.shortcut],
|
||||
[toggleShowSideBar, state === 'disabled', configContext.value.shortcut],
|
||||
)
|
||||
|
||||
const intelligentToggle = configContext.value.intelligentToggle
|
||||
// Hide sidebar when error due to auth but token is set #128
|
||||
const hideSidebarOnInvalidToken: boolean =
|
||||
intelligentToggle === null && Boolean(status === 'error-due-to-auth' && accessToken)
|
||||
intelligentToggle === null && Boolean(state === 'error-due-to-auth' && accessToken)
|
||||
React.useEffect(() => {
|
||||
if (hideSidebarOnInvalidToken) {
|
||||
props.setShouldShow(false)
|
||||
|
|
@ -121,7 +121,7 @@ const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
|||
</div>
|
||||
<div className={'gitako-side-bar-content'}>
|
||||
{(() => {
|
||||
switch (status) {
|
||||
switch (state) {
|
||||
case 'loading-meta':
|
||||
return <LoadingIndicator text={'Fetching repo meta...'} />
|
||||
case 'loading-tree':
|
||||
|
|
@ -164,7 +164,7 @@ const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
|||
RawGitako.defaultProps = {
|
||||
shouldShow: false,
|
||||
showSettings: false,
|
||||
status: 'loading-meta',
|
||||
state: 'loading-meta',
|
||||
}
|
||||
|
||||
export const SideBar = connect(SideBarCore)(RawGitako)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export type ConnectorState = {
|
|||
metaData?: MetaData
|
||||
// file tree data
|
||||
treeData?: TreeNode
|
||||
status: 'loading-meta' | 'loading-tree' | 'idle' | 'error-due-to-auth' | 'disabled'
|
||||
state: 'loading-meta' | 'loading-tree' | 'idle' | 'error-due-to-auth' | 'disabled'
|
||||
logoContainerElement: Element | null
|
||||
defer?: boolean
|
||||
} & {
|
||||
|
|
@ -37,10 +37,10 @@ export const init: BoundMethodCreator = dispatch => async () => {
|
|||
const leave = await promiseQueue.enter()
|
||||
|
||||
try {
|
||||
dispatch.set({ status: 'loading-meta' })
|
||||
dispatch.set({ state: 'loading-meta' })
|
||||
const metaData = platform.resolveMeta()
|
||||
if (!metaData) {
|
||||
dispatch.set({ status: 'disabled' })
|
||||
dispatch.set({ state: 'disabled' })
|
||||
return
|
||||
}
|
||||
const { userName, repoName, branchName } = metaData
|
||||
|
|
@ -113,9 +113,9 @@ export const init: BoundMethodCreator = dispatch => async () => {
|
|||
}
|
||||
}
|
||||
|
||||
dispatch.set({ status: 'loading-tree' })
|
||||
dispatch.set({ state: 'loading-tree' })
|
||||
const { root: treeData, defer } = await getTreeData
|
||||
dispatch.set({ status: 'idle', treeData, defer })
|
||||
dispatch.set({ state: 'idle', treeData, defer })
|
||||
} catch (err) {
|
||||
dispatch.call(handleError, err)
|
||||
}
|
||||
|
|
@ -133,13 +133,13 @@ export const handleError: BoundMethodCreator<[Error]> = dispatch => async err =>
|
|||
err.message === errors.BAD_CREDENTIALS ||
|
||||
err.message === errors.API_RATE_LIMIT
|
||||
) {
|
||||
dispatch.set({ status: 'error-due-to-auth' })
|
||||
dispatch.set({ state: 'error-due-to-auth' })
|
||||
} else if (err.message === errors.CONNECTION_BLOCKED) {
|
||||
const { props } = dispatch.get()
|
||||
if (props.configContext.value.accessToken) {
|
||||
dispatch.call(setError, `Cannot connect to ${platformName}.`)
|
||||
} else {
|
||||
dispatch.set({ status: 'error-due-to-auth' })
|
||||
dispatch.set({ state: 'error-due-to-auth' })
|
||||
}
|
||||
} else if (err.message === errors.SERVER_FAULT) {
|
||||
dispatch.call(setError, `${platformName} server went down.`)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export type Config = {
|
|||
compressSingletonFolder: boolean
|
||||
copyFileButton: boolean
|
||||
copySnippetButton: boolean
|
||||
intelligentToggle: boolean | null // `null` stands for intelligent, boolean for sidebar open status
|
||||
intelligentToggle: boolean | null // `null` stands for intelligent, boolean for sidebar open state
|
||||
icons: 'rich' | 'dim' | 'native'
|
||||
toggleButtonVerticalDistance: number
|
||||
toggleButtonContent: 'logo' | 'octoface'
|
||||
|
|
|
|||
Loading…
Reference in a new issue