Skip to content

Commit

Permalink
merge of #4459
Browse files Browse the repository at this point in the history
  • Loading branch information
lelemm committed Mar 5, 2025
1 parent 90d457d commit a2b0fd8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
7 changes: 4 additions & 3 deletions packages/desktop-client/src/components/accounts/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
type TransactionFilterEntity,
} from 'loot-core/types/models';

import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useLocale } from '../../hooks/useLocale';
import { useLocalPref } from '../../hooks/useLocalPref';
import { useSplitsExpanded } from '../../hooks/useSplitsExpanded';
import { useSyncServerStatus } from '../../hooks/useSyncServerStatus';
Expand Down Expand Up @@ -188,7 +188,6 @@ export function AccountHeader({
onMakeAsNonSplitTransactions,
}: AccountHeaderProps) {
const { t } = useTranslation();
const [language] = useGlobalPref('language');

const [menuOpen, setMenuOpen] = useState(false);
const [reconcileOpen, setReconcileOpen] = useState(false);
Expand All @@ -201,6 +200,8 @@ export function AccountHeader({
const isServerOffline = syncServerStatus === 'offline';
const [_, setExpandSplitsPref] = useLocalPref('expand-splits');

const locale = useLocale();

let canSync = !!(account?.account_id && isUsingServer);
if (!account) {
// All accounts - check for any syncable account
Expand Down Expand Up @@ -388,7 +389,7 @@ export function AccountHeader({
}}
content={
account?.last_reconciled
? `${t('Reconciled')} ${tsToRelativeTime(account.last_reconciled, language || 'en-US')}`
? `${t('Reconciled')} ${tsToRelativeTime(account.last_reconciled, locale)}`
: t('Not yet reconciled')
}
placement="top"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Button } from '@actual-app/components/button';
import { tsToRelativeTime } from 'loot-core/shared/util';
import { type AccountEntity } from 'loot-core/src/types/models';

import { useGlobalPref } from '../../hooks/useGlobalPref';
import { theme } from '../../style';
import { Row, Cell } from '../table';

Expand All @@ -15,15 +14,14 @@ type AccountRowProps = {
hovered: boolean;
onHover: (id: AccountEntity['id'] | null) => void;
onAction: (account: AccountEntity, action: 'link' | 'edit') => void;
locale: Locale;
};

export const AccountRow = memo(
({ account, hovered, onHover, onAction }: AccountRowProps) => {
({ account, hovered, onHover, onAction, locale }: AccountRowProps) => {
const backgroundFocus = hovered;

const [language = 'en-US'] = useGlobalPref('language');

const lastSync = tsToRelativeTime(account.last_sync, language, {
const lastSync = tsToRelativeTime(account.last_sync, locale, {
capitalize: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { View } from '@actual-app/components/view';

import { type AccountEntity } from 'loot-core/src/types/models';

import { useLocale } from '../../hooks/useLocale';

import { AccountRow } from './AccountRow';

type AccountsListProps = {
Expand All @@ -19,6 +21,8 @@ export function AccountsList({
onHover,
onAction,
}: AccountsListProps) {
const locale = useLocale();

if (accounts.length === 0) {
return null;
}
Expand All @@ -39,6 +43,7 @@ export function AccountsList({
hovered={hovered}
onHover={onHover}
onAction={onAction}
locale={locale}
/>
);
})}
Expand Down
6 changes: 1 addition & 5 deletions packages/loot-core/src/shared/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-strict-ignore
import { formatDistanceToNow } from 'date-fns';
import * as locales from 'date-fns/locale';

export function last<T>(arr: Array<T>) {
return arr[arr.length - 1];
Expand Down Expand Up @@ -489,17 +488,14 @@ export function sortByKey<T>(arr: T[], key: keyof T): T[] {

export function tsToRelativeTime(
ts: string | null,
language: string,
locale: Locale,
options: {
capitalize: boolean;
} = { capitalize: false },
): string {
if (!ts) return 'Unknown';

const parsed = new Date(parseInt(ts, 10));
const locale =
locales[language.replace('-', '') as keyof typeof locales] ??
locales['enUS'];

let distance = formatDistanceToNow(parsed, { addSuffix: true, locale });

Expand Down

0 comments on commit a2b0fd8

Please sign in to comment.