Skip to content

Commit

Permalink
Merge pull request #3 from pullflow/fix/offline-icon
Browse files Browse the repository at this point in the history
Fix: Extension should show offline in status bar without notification
  • Loading branch information
hassan-pullflow authored Oct 31, 2023
2 parents 53c0d0e + cbc763c commit 5d4d755
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/commands/reconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ export const Reconnect = async (
userAuthoredCodeReviews: codeReviews.data.authored,
})
StatusBar.update({ context, statusBar, state: StatusBarState.SignedIn })

commands.executeCommand(Command.activePullRequests)

return
}
3 changes: 0 additions & 3 deletions src/utils/pullRequestsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export const PullRequestState = {
if (errorCount.count >= MAX_ERROR_COUNT) {
StatusBar.update({ context, statusBar, state: StatusBarState.Error })
}
window.showErrorMessage(
`Pullflow: Couldn't fetch pull requests. ${codeReviews.error.message}`
)
return
}
await Store.set(context, {
Expand Down
29 changes: 21 additions & 8 deletions src/views/statusBar/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ export const StatusBar = {
log.info('updating status bar', module)

if (state === StatusBarState.SignedIn) {
statusBarProperties.signedIn.text = getStatusBarText(context)
statusBarProperties.signedIn.text = getStatusBarText({ context })
statusBar = Object.assign(statusBar, statusBarProperties.signedIn)
} else if (state === StatusBarState.Loading) {
statusBar = Object.assign(statusBar, statusBarProperties.loading)
} else if (state === StatusBarState.Error) {
statusBarProperties.error.text = getStatusBarText({
context,
showErrorIcon: true,
})
statusBar = Object.assign(statusBar, statusBarProperties.error)
} else {
statusBar = Object.assign(statusBar, statusBarProperties.signedOut)
Expand All @@ -82,7 +86,13 @@ export const StatusBar = {
}

/** computes status bar text */
function getStatusBarText(context: ExtensionContext): string {
function getStatusBarText({
context,
showErrorIcon = false,
}: {
context: ExtensionContext
showErrorIcon?: boolean
}): string {
if (STATUS_BAR_ICON_PREVIEW) {
const allIcons = IconReference.map((k) => `$(${k})`).join('')
return '$(pullflow-icon)' + allIcons
Expand All @@ -93,12 +103,15 @@ function getStatusBarText(context: ExtensionContext): string {
previousPresenceStatus,
} = Store.get(context)

if (!pendingUserCodeReviews && !userAuthoredCodeReviews) return ''
const presenceIcon =
previousPresenceStatus === PresenceStatus.Flow ? '$(symbol-event)' : ''
const errorIcon = showErrorIcon ? ' $(warning) ' : ''

if (!pendingUserCodeReviews && !userAuthoredCodeReviews)
return `${errorIcon} ${presenceIcon} $(pullflow-icon)`

const pendingCodeReviewsCount = pendingUserCodeReviews?.length || 0
const authoredCodeReviewsCount = userAuthoredCodeReviews?.length || 0
const presenceIcon =
previousPresenceStatus === PresenceStatus.Flow ? '$(symbol-event)' : ''
if (
pendingCodeReviewsCount < MAX_PR_COUNT &&
authoredCodeReviewsCount < MAX_PR_COUNT
Expand All @@ -111,10 +124,10 @@ function getStatusBarText(context: ExtensionContext): string {
userAuthoredCodeReviews?.map(
(codeReview) => `$(${PullRequestIcons.getIcon(codeReview.botReaction)})`
) || []
return `${presenceIcon} ${pendingCodeReviewIcons.join(
return `${errorIcon} ${presenceIcon} ${pendingCodeReviewIcons.join(
''
)} $(pullflow-icon)\t${authoredCodeReviewIcons.join('')}`
)} $(pullflow-icon) ${authoredCodeReviewIcons.join('')}`
} else {
return `${presenceIcon} ${pendingCodeReviewsCount} $(pullflow-icon) ${authoredCodeReviewsCount}`
return `${errorIcon} ${presenceIcon} ${pendingCodeReviewsCount} $(pullflow-icon) ${authoredCodeReviewsCount}`
}
}

0 comments on commit 5d4d755

Please sign in to comment.