Skip to content

Commit

Permalink
Continued working on human friendly dates (#609). Added missing trans…
Browse files Browse the repository at this point in the history
…lations. Updated dependencies.
  • Loading branch information
ransome1 committed Mar 4, 2024
1 parent bffaeeb commit 5faba0f
Show file tree
Hide file tree
Showing 23 changed files with 358 additions and 279 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/close-stale-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
in 15 days from now. Your efforts are greatly appreciated, and we
value your contributions to the project.
stale-issue-label: no-issue-activity
days-before-stale: 90
days-before-stale: 120
days-before-close: 15
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sleek",
"version": "2.0.12-rc.2",
"version": "2.0.12-rc.3",
"description": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"synopsis": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"keywords": [
Expand Down
2 changes: 2 additions & 0 deletions src/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "příští týden",
"drawer.attributes.yesterday": "včera",
"drawer.attributes.lastWeek": "minulý týden",
"drawer.attributes.thisWeek": "tento týden",
"drawer.attributes.thisMonth": "tento měsíc",
"drawer.sorting.fileSorting": "Seřadit úkoly podle pořadí v souboru",
"shared.attributeMapping.t": "Termín",
"shared.attributeMapping.due": "Termín splnění",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "nächste Woche",
"drawer.attributes.yesterday": "gestern",
"drawer.attributes.lastWeek": "letzte Woche",
"drawer.attributes.thisWeek": "diese Woche",
"drawer.attributes.thisMonth": "diesen Monat",
"drawer.sorting.fileSorting": "Aufgaben in der Reihenfolge der Datei anordnen",
"shared.attributeMapping.t": "Schwellenwertdatum",
"shared.attributeMapping.due": "Fälligkeitsdatum",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en-gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "next week",
"drawer.attributes.yesterday": "yesterday",
"drawer.attributes.lastWeek": "last week",
"drawer.attributes.thisWeek": "this week",
"drawer.attributes.thisMonth": "this month",
"drawer.sorting.fileSorting": "Order todos as they appear in the file",
"shared.attributeMapping.t": "Threshold date",
"shared.attributeMapping.due": "Due date",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "next week",
"drawer.attributes.yesterday": "yesterday",
"drawer.attributes.lastWeek": "last week",
"drawer.attributes.thisWeek": "this week",
"drawer.attributes.thisMonth": "this month",
"drawer.sorting.fileSorting": "Order todos as they appear in the file",
"shared.attributeMapping.t": "Threshold date",
"shared.attributeMapping.due": "Due date",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"drawer.attributes.nextWeek": "próxima semana",
"drawer.attributes.yesterday": "ayer",
"drawer.attributes.lastWeek": "la semana pasada",
"drawer.attributes.thisWeek": "esta semana",
"drawer.attributes.thisMonth": "este mes",
"drawer.sorting.fileSorting": "Ordenar tareas como aparecen en el archivo",
"shared.attributeMapping.t": "Fecha umbral",
"shared.attributeMapping.due": "Fecha de vencimiento",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "la semaine prochaine",
"drawer.attributes.yesterday": "hier",
"drawer.attributes.lastWeek": "la semaine dernière",
"drawer.attributes.thisWeek": "cette semaine",
"drawer.attributes.thisMonth": "ce mois",
"drawer.sorting.fileSorting": "Classer les tâches comme elles apparaissent dans le fichier",
"shared.attributeMapping.t": "Date limite",
"shared.attributeMapping.due": "Date d'échéance",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "अगले हफ्ते",
"drawer.attributes.yesterday": "कल",
"drawer.attributes.lastWeek": "पिछले हफ्ते",
"drawer.attributes.thisWeek": "इस सप्ताह",
"drawer.attributes.thisMonth": "इस महीने",
"drawer.sorting.fileSorting": "वे दिखाई देते हैं जैसे कि वे फ़ाइल में हैं, कार्य क्रमबद्ध करें",
"shared.attributeMapping.t": "सीमा तिथि",
"shared.attributeMapping.due": "समापन तिथि",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "jövő hét",
"drawer.attributes.yesterday": "tegnap",
"drawer.attributes.lastWeek": "múlt hét",
"drawer.attributes.thisWeek": "ez a hét",
"drawer.attributes.thisMonth": "ez a hónap",
"drawer.sorting.fileSorting": "Feladatok rendezése, ahogy megjelennek a fájlban",
"shared.attributeMapping.t": "Hátralévő dátum",
"shared.attributeMapping.due": "Határidő",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "la prossima settimana",
"drawer.attributes.yesterday": "ieri",
"drawer.attributes.lastWeek": "la settimana scorsa",
"drawer.attributes.thisWeek": "questa settimana",
"drawer.attributes.thisMonth": "questo mese",
"drawer.sorting.fileSorting": "Ordina i compiti come appaiono nel file",
"shared.attributeMapping.t": "Data di scadenza",
"shared.attributeMapping.due": "Data di scadenza",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "来週",
"drawer.attributes.yesterday": "昨日",
"drawer.attributes.lastWeek": "先週",
"drawer.attributes.thisWeek": "今週",
"drawer.attributes.thisMonth": "今月",
"drawer.sorting.fileSorting": "ファイルに表示される順にタスクを並べ替え",
"shared.attributeMapping.t": "期限日",
"shared.attributeMapping.due": "期日",
Expand Down
4 changes: 3 additions & 1 deletion src/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"drawer.attributes.tomorrow": "내일",
"drawer.attributes.nextWeek": "다음 주",
"drawer.attributes.yesterday": "어제",
"drawer.attributes.lastWeek": "지난 주",
"drawer.attributes.lastWeek": "지난 주",
"drawer.attributes.thisWeek": "이번 주",
"drawer.attributes.thisMonth": "이번 달",
"drawer.sorting.fileSorting": "파일에 나타나는 대로 작업 정렬",
"shared.attributeMapping.t": "임계 날짜",
"shared.attributeMapping.due": "마감일",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "następny tydzień",
"drawer.attributes.yesterday": "wczoraj",
"drawer.attributes.lastWeek": "ostatni tydzień",
"drawer.attributes.thisWeek": "w tym tygodniu",
"drawer.attributes.thisMonth": "w tym miesiącu",
"drawer.sorting.fileSorting": "Sortuj zadania tak, jak występują w pliku",
"shared.attributeMapping.t": "Data progowa",
"shared.attributeMapping.due": "Termin",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "próxima semana",
"drawer.attributes.yesterday": "ontem",
"drawer.attributes.lastWeek": "semana passada",
"drawer.attributes.thisWeek": "esta semana",
"drawer.attributes.thisMonth": "este mês",
"drawer.sorting.fileSorting": "Ordenar tarefas como aparecem no ficheiro",
"shared.attributeMapping.t": "Data de limite",
"shared.attributeMapping.due": "Data de vencimento",
Expand Down
4 changes: 3 additions & 1 deletion src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"drawer.attributes.tomorrow": "завтра",
"drawer.attributes.nextWeek": "на следующей неделе",
"drawer.attributes.yesterday": "вчера",
"drawer.attributes.lastWeek": "на прошлой неделе",
"drawer.attributes.lastWeek": "на прошлой неделе",
"drawer.attributes.thisWeek": "на этой неделе",
"drawer.attributes.thisMonth": "в этом месяце",
"drawer.sorting.fileSorting": "Сортировать задачи в порядке их появления в файле",
"shared.attributeMapping.t": "Дата порога",
"shared.attributeMapping.due": "Дата выполнения",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"drawer.attributes.nextWeek": "на следующей неделе",
"drawer.attributes.yesterday": "вчера",
"drawer.attributes.lastWeek": "на прошлой неделе",
"drawer.attributes.thisWeek": "bu hafta",
"drawer.attributes.thisMonth": "bu ay",
"drawer.sorting.fileSorting": "Görevleri dosyada göründükleri sıraya göre sırala",
"shared.attributeMapping.t": "Eşik tarihi",
"shared.attributeMapping.due": "Bitiş tarihi",
Expand Down
4 changes: 3 additions & 1 deletion src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"drawer.attributes.tomorrow": "明天",
"drawer.attributes.nextWeek": "下周",
"drawer.attributes.yesterday": "昨天",
"drawer.attributes.lastWeek": "上周",
"drawer.attributes.lastWeek": "上周",
"drawer.attributes.thisWeek": "本周",
"drawer.attributes.thisMonth": "本月",
"drawer.sorting.fileSorting": "按照它们在文件中出现的顺序排序任务",
"shared.attributeMapping.t": "阈值日期",
"shared.attributeMapping.due": "截止日期",
Expand Down
1 change: 0 additions & 1 deletion src/renderer/Dialog/RecurrencePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const RecurrencePicker: React.FC<RecurrencePickerProps> = ({
const getInterval = (recurrence) => recurrence ? recurrence.match(/[a-zA-Z]+/) : null;
const getAmount = (recurrence) => recurrence ? recurrence.match(/\d+/) : null;
const getStrictIndicator = (recurrence: string | null) => !!recurrence?.startsWith('+');

setStrictRecurrence(getStrictIndicator(recurrence));
setInterval(getInterval(recurrence));
setAmount(getAmount(recurrence));
Expand Down
57 changes: 33 additions & 24 deletions src/renderer/Drawer/Attributes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { withTranslation, WithTranslation } from 'react-i18next';
import { i18n } from '../Settings/LanguageSelector';
import './Attributes.scss';


const { store } = window.api;

interface DrawerAttributesProps extends WithTranslation {
Expand All @@ -31,42 +30,52 @@ const DrawerAttributes: React.FC<DrawerAttributesProps> = memo(({
const firstTabbableElementRef = useRef<HTMLDivElement | null>(null);
const [hovered, setHovered] = useState<string | null>(null);

const isAttributesEmpty = useMemo(
() => !attributes || Object.values(attributes).every((attribute) => !Object.keys(attribute).length),
[attributes]
);

const preprocessAttributes = (attributeKey, attributes) => {
if (!attributes) {
return null;
}

const isDate: boolean = ['due', 't', 'completed', 'created'].includes(attributeKey);
const isDate = ['due', 't', 'completed', 'created'].includes(attributeKey);
const processedAttributes = {};

Object.keys(attributes).forEach((key) => {
if (attributes[key]) {
const count = attributes[key].count;
const formattedValue = settings.useHumanFriendlyDates && isDate ? friendlyDate(key, t) : key;

if (!processedAttributes[formattedValue]) {
processedAttributes[formattedValue] = {
key: attributeKey,
name: formattedValue,
count,
notify: attributes[key].notify,
aggregatedValues: [key]
};
} else {
processedAttributes[formattedValue].count += count;
processedAttributes[formattedValue].notify = processedAttributes[formattedValue].notify || attributes[key].notify;
processedAttributes[formattedValue].aggregatedValues.push(key);
}
const formattedValues = settings.useHumanFriendlyDates && isDate ? friendlyDate(key, settings.language, t) : [key];

formattedValues.forEach((formattedValue) => {
if (!processedAttributes[formattedValue]) {
processedAttributes[formattedValue] = {
key: attributeKey,
name: formattedValue,
count,
notify: attributes[key].notify,
aggregatedValues: [key]
};
} else {
processedAttributes[formattedValue].count += count;
processedAttributes[formattedValue].notify = processedAttributes[formattedValue].notify || attributes[key].notify;
processedAttributes[formattedValue].aggregatedValues.push(key);
}
});
}
});

return processedAttributes;
};
const sortedAttributes = Object.fromEntries(
Object.entries(processedAttributes).sort(([, a], [, b]) => {
const lastDateA = a.aggregatedValues.length > 0 ? a.aggregatedValues[a.aggregatedValues.length - 1] : 0;
const lastDateB = b.aggregatedValues.length > 0 ? b.aggregatedValues[b.aggregatedValues.length - 1] : 0;
return new Date(lastDateA).getTime() - new Date(lastDateB).getTime();
})
);

const isAttributesEmpty = useMemo(
() => !attributes || Object.values(attributes).every((attribute) => !Object.keys(attribute).length),
[attributes]
);
return sortedAttributes;
};

const handleAccordionToggle = (index: number) => {
const updatedAccordionOpenState = settings.accordionOpenState;
Expand Down Expand Up @@ -143,8 +152,8 @@ const DrawerAttributes: React.FC<DrawerAttributesProps> = memo(({
return (
<div id="Attributes" ref={firstTabbableElementRef}>
{!isAttributesEmpty ? (
Object.keys(attributes).map((key, index) => {

Object.keys(attributes).map((key, index) => {
const preprocessedAttributes: Attributes = preprocessAttributes(key, attributes[key]);
const attributeHeadline: string = translatedAttributes(t)[key];

Expand Down
29 changes: 7 additions & 22 deletions src/renderer/Grid/DatePickerInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import Button from '@mui/material/Button';
import Chip from '@mui/material/Chip';
import Badge from '@mui/material/Badge';
import { handleFilterSelect } from '../Shared';
import { handleFilterSelect, friendlyDate } from '../Shared';
import { withTranslation } from 'react-i18next';
import { i18n } from '../Settings/LanguageSelector';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import duration from 'dayjs/plugin/duration';
import calendar from 'dayjs/plugin/calendar';
dayjs.extend(relativeTime);
dayjs.extend(duration);
dayjs.extend(calendar);

const { ipcRenderer } = window.api;

Expand All @@ -37,19 +31,6 @@ const DatePickerInline: React.FC<Props> = ({
const [open, setOpen] = useState(false);
const chipText = type === 'due' ? "due:" : type === 't' ? "t:" : null;

dayjs.locale(settings.language);

const friendlyDate = (value) => dayjs(value).calendar(null, {
sameDay: `[${t(`drawer.attributes.today`)}]`,
nextDay: `[${t(`drawer.attributes.tomorrow`)}]`,
nextWeek: `[${t(`drawer.attributes.nextWeek`)}]`,
lastDay: `[${t(`drawer.attributes.yesterday`)}]`,
lastWeek: `[${t(`drawer.attributes.lastWeek`)}]`,
sameElse: function () {
return dayjs(this).fromNow();
}
});

const handleChange = (date: dayjs.Dayjs | null) => {
try {
ipcRenderer.send('writeTodoToFile', todoObject.id, todoObject.string, false, type, dayjs(date).format('YYYY-MM-DD'));
Expand All @@ -74,8 +55,12 @@ const DatePickerInline: React.FC<Props> = ({
const ButtonField = ({ ...props }) => {
const { disabled, InputProps: { ref } = {}, inputProps: { 'aria-label': ariaLabel } = {} } = props;
const mustNotify = (type === 'due') ? !todoObject?.notify : true;
const formattedValue = settings.useHumanFriendlyDates && dayjs(date).isValid() ? friendlyDate(date, settings.language) : date;
const selected = filters && type !== null && (filters[type as keyof Filters] || []).some((filter: Filter) => filter.name === formattedValue);
const formattedValue = settings.useHumanFriendlyDates && dayjs(date).isValid() ? friendlyDate(date, settings.language, t)[0] : date;

const selected = filters && type !== null && (filters[type as keyof Filters] || []).some((filter: Filter) => {
return filter.values.includes(date);
});

return (
<span className={selected ? 'selected' : null} data-todotxt-attribute={type}>
<Button id={props.id} disabled={disabled} ref={ref} aria-label={ariaLabel} tabIndex={-1}>
Expand Down
Loading

0 comments on commit 5faba0f

Please sign in to comment.