Skip to content

Commit

Permalink
refactor: minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
f3rno64 committed Nov 29, 2023
1 parent 4263d3c commit b3cdd86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/commands/now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const handler = (args: NowCommandArguments) => {
)

const [sheet] = sheetsWithActiveEntries
const { activeEntryID, entries } = sheet
const { name, activeEntryID, entries } = sheet
const entry = entries.find(({ id }) => id === activeEntryID)

P.printSheetEntry(entry, true)
P.printSheetEntry(entry, true, name)
}

export default {
Expand Down
14 changes: 12 additions & 2 deletions src/print/sheet_entry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import ago from 's-ago'
import colors from 'colors'
import _isEmpty from 'lodash/isEmpty'
import formatDuration from 'format-duration'

import * as C from '../color'
import { type TimeSheetEntry } from '../types'

const printSheetEntry = (entry: TimeSheetEntry, isActive?: boolean): void => {
const printSheetEntry = (
entry: TimeSheetEntry,
isActive?: boolean,
sheetName?: string
): void => {
const { id, start, end, description } = entry
const idUI = C.clID(`${id}`)
const startUI = C.clDateAgo(ago(start))
Expand All @@ -15,7 +20,12 @@ const printSheetEntry = (entry: TimeSheetEntry, isActive?: boolean): void => {
const endedUI = end === null ? '' : C.clDateAgo(ago(end))
const startEndUI = end === null ? `started ${startUI}` : `ended ${endedUI}`

let result = `(${idUI}) [${durationUI}] ${descriptionUI}`
const sheetNamePrefix = _isEmpty(sheetName)
? ''
: `${C.clText('sheet')} ${C.clSheet(sheetName)}`

let result =
`${sheetNamePrefix} (${idUI}) [${durationUI}] ${descriptionUI}`.trim()

if (end === null) {
result += `: ${startEndUI}`
Expand Down

0 comments on commit b3cdd86

Please sign in to comment.