Skip to content

Commit

Permalink
[ENG-1530] Display item count alongside labels (#2011)
Browse files Browse the repository at this point in the history
* display count alonside labels

* format

* attempt i18n

* item_with_count
  • Loading branch information
Brendonovich authored Jan 29, 2024
1 parent f9e8275 commit 8a57d59
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 9 deletions.
1 change: 0 additions & 1 deletion core/src/api/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
Ok(library.db.label().find_many(vec![]).exec().await?)
})
})
//
.procedure("listWithThumbnails", {
R.with2(library())
.query(|(_, library), cursor: label::name::Type| async move {
Expand Down
25 changes: 24 additions & 1 deletion interface/app/$libraryId/Explorer/View/GridView/Item/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import clsx from 'clsx';
import { memo, useMemo } from 'react';
import { byteSize, getItemFilePath, useSelector, type ExplorerItem } from '@sd/client';
import { byteSize, getItemFilePath, useSelector, type ExplorerItem, useLibraryQuery } from '@sd/client';

import { useLocale } from '~/hooks';
import { useExplorerContext } from '../../../Context';
import { ExplorerDraggable } from '../../../ExplorerDraggable';
import { ExplorerDroppable, useExplorerDroppableContext } from '../../../ExplorerDroppable';
Expand Down Expand Up @@ -109,6 +110,7 @@ const ItemMetadata = () => {
selected={item.selected}
/>
<ItemSize />
{item.data.type === "Label" && <LabelItemCount data={item.data} />}
</ExplorerDraggable>
);
};
Expand Down Expand Up @@ -145,3 +147,24 @@ const ItemSize = () => {
</div>
);
};

function LabelItemCount({data}: {data: Extract<ExplorerItem, {type: "Label"}>}) {
const { t } = useLocale();

const count = useLibraryQuery(["search.objectsCount", {
filters: [{
object: {
labels: {
in: [data.item.id]
}
}
}]
}])

if(count.data === undefined) return

return <div className="truncate rounded-md px-1.5 py-[1px] text-center text-tiny text-ink-dull">
{t("item_with_count", {count: count.data})}
</div>

}
4 changes: 3 additions & 1 deletion interface/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,7 @@
"your_account": "Ihr Konto",
"your_account_description": "Spacedrive-Konto und -Informationen.",
"your_local_network": "Ihr lokales Netzwerk",
"your_privacy": "Ihre Privatsphäre"
"your_privacy": "Ihre Privatsphäre",
"item_with_count_one": "{{count}} artikel",
"item_with_count_other": "{{count}} artikel"
}
4 changes: 3 additions & 1 deletion interface/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,7 @@
"your_account": "Your account\"",
"your_account_description": "Spacedrive account and information.",
"your_local_network": "Your Local Network",
"your_privacy": "Your Privacy"
"your_privacy": "Your Privacy",
"item_with_count_one": "{{count}} item",
"item_with_count_other": "{{count}} items"
}
4 changes: 3 additions & 1 deletion interface/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,7 @@
"your_account": "Tu cuenta",
"your_account_description": "Cuenta de Spacedrive e información.",
"your_local_network": "Tu Red Local",
"your_privacy": "Tu Privacidad"
"your_privacy": "Tu Privacidad",
"item_with_count_one": "{{count}} artículo",
"item_with_count_other": "{{count}} artículos"
}
4 changes: 3 additions & 1 deletion interface/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,7 @@
"your_account": "Votre compte",
"your_account_description": "Compte et informations Spacedrive.",
"your_local_network": "Votre réseau local",
"your_privacy": "Votre confidentialité"
"your_privacy": "Votre confidentialité",
"item_with_count_one": "{{count}} article",
"item_with_count_other": "{{count}} articles"
}
4 changes: 3 additions & 1 deletion interface/locales/tr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,7 @@
"your_account": "Hesabınız",
"your_account_description": "Spacedrive hesabınız ve bilgileri.",
"your_local_network": "Yerel Ağınız",
"your_privacy": "Gizliliğiniz"
"your_privacy": "Gizliliğiniz",
"item_with_count_one": "{{count}} madde",
"item_with_count_other": "{{count}} maddeler"
}
4 changes: 3 additions & 1 deletion interface/locales/zh-CN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,7 @@
"your_account": "您的账户",
"your_account_description": "Spacedrive账号和信息。",
"your_local_network": "您的本地网络",
"your_privacy": "您的隐私"
"your_privacy": "您的隐私",
"item_with_count_one": "{{count}} 项目",
"item_with_count_other": "{{count}} 项目"
}
4 changes: 3 additions & 1 deletion interface/locales/zh-TW/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,7 @@
"your_account": "您的帳戶",
"your_account_description": "Spacedrive帳戶和資訊。",
"your_local_network": "您的本地網路",
"your_privacy": "您的隱私"
"your_privacy": "您的隱私",
"item_with_count_one": "{{count}} 项目",
"item_with_count_other": "{{count}} 项目"
}

0 comments on commit 8a57d59

Please sign in to comment.