mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-04 14:55:34 +00:00
Some checks failed
Build / 🚀 Deploy to test env (fly.io) (push) Has been cancelled
Build / Manual Approval (push) Has been cancelled
Build / 🛠 Build (1.17, 18.x, 27) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/amd64) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/arm64) (push) Has been cancelled
Build / merge (push) Has been cancelled
Build / 🏷 Create Release (push) Has been cancelled
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { LabelsManager } from '@/hooks/Mapper/utils/labelsManager';
|
|
import { LABELS_INFO, LABELS_ORDER } from '@/hooks/Mapper/components/map/constants';
|
|
interface UseLabelsInfoParams {
|
|
labels: string | null;
|
|
linkedSigPrefix: string | null;
|
|
isShowLinkedSigId: boolean;
|
|
}
|
|
|
|
export type LabelInfo = {
|
|
id: string;
|
|
shortName: string;
|
|
};
|
|
|
|
function sortedLabels(labels: string[]): LabelInfo[] {
|
|
if (!labels) return [];
|
|
return LABELS_ORDER.filter(x => labels.includes(x)).map(x => LABELS_INFO[x] as LabelInfo);
|
|
}
|
|
|
|
export function useLabelsInfo({ labels, linkedSigPrefix, isShowLinkedSigId }: UseLabelsInfoParams) {
|
|
const labelsManager = useMemo(() => new LabelsManager(labels ?? ''), [labels]);
|
|
const labelsInfo = useMemo(() => sortedLabels(labelsManager.list), [labelsManager]);
|
|
const labelCustom = useMemo(() => {
|
|
if (isShowLinkedSigId && linkedSigPrefix) {
|
|
return labelsManager.customLabel ? `${linkedSigPrefix}・${labelsManager.customLabel}` : linkedSigPrefix;
|
|
}
|
|
return labelsManager.customLabel;
|
|
}, [linkedSigPrefix, isShowLinkedSigId, labelsManager]);
|
|
|
|
return { labelsInfo, labelCustom };
|
|
}
|