fix(m0001_ct0002): ensure Extra Points is displayed at the end after Du Channel
This commit is contained in:
parent
da7e3e0bea
commit
a1c9da8ca6
|
|
@ -1,12 +1,45 @@
|
||||||
import React from "react";
|
import React, { useMemo } from "react";
|
||||||
import { Pressable, Text, View } from "react-native";
|
import { Pressable, Text, View } from "react-native";
|
||||||
import { asNumber, asString, asStringArray } from "../helpers/value";
|
import { asNumber, asString, asStringArray } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { StandardIndexCard } from "../shared/StandardIndexCard";
|
import { StandardIndexCard } from "../shared/StandardIndexCard";
|
||||||
import type { CollectionItemRendererProps, CollectionRendererProps } from "../../types/renderer.types";
|
import type {
|
||||||
|
CollectionItemRendererProps,
|
||||||
|
CollectionRendererProps,
|
||||||
|
SearchResultItem,
|
||||||
|
} from "../../types/renderer.types";
|
||||||
|
|
||||||
|
function sortWithExtraPointsAfterDu(items: SearchResultItem[]): SearchResultItem[] {
|
||||||
|
const isExtra = (item: SearchResultItem) => {
|
||||||
|
const name = (asString(item.attributes.name) || item.title || "").toLowerCase();
|
||||||
|
const code = (asString(item.attributes.code) || item.slug || "").toLowerCase();
|
||||||
|
return name.includes("extra") || code.includes("extra");
|
||||||
|
};
|
||||||
|
|
||||||
|
const extraItems = items.filter(isExtra);
|
||||||
|
const regularItems = items.filter((item) => !isExtra(item));
|
||||||
|
|
||||||
|
regularItems.sort((a, b) => {
|
||||||
|
const aOrder =
|
||||||
|
typeof a.attributes.sort_order === "number"
|
||||||
|
? a.attributes.sort_order
|
||||||
|
: 999;
|
||||||
|
const bOrder =
|
||||||
|
typeof b.attributes.sort_order === "number"
|
||||||
|
? b.attributes.sort_order
|
||||||
|
: 999;
|
||||||
|
return aOrder - bOrder;
|
||||||
|
});
|
||||||
|
|
||||||
|
return [...regularItems, ...extraItems];
|
||||||
|
}
|
||||||
|
|
||||||
export function MeridianIndexCollectionRenderer(props: CollectionRendererProps) {
|
export function MeridianIndexCollectionRenderer(props: CollectionRendererProps) {
|
||||||
return <CollectionScaffold {...props} />;
|
const sortedItems = useMemo(
|
||||||
|
() => sortWithExtraPointsAfterDu(props.items),
|
||||||
|
[props.items],
|
||||||
|
);
|
||||||
|
return <CollectionScaffold {...props} items={sortedItems} />;
|
||||||
}
|
}
|
||||||
export function MeridianCollectionRenderer(props: CollectionRendererProps) {
|
export function MeridianCollectionRenderer(props: CollectionRendererProps) {
|
||||||
return <CollectionScaffold {...props} />;
|
return <CollectionScaffold {...props} />;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,44 @@
|
||||||
import React from "react";
|
import React, { useMemo } from "react";
|
||||||
import { asString } from "../helpers/value";
|
import { asString } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { StandardIndexCard } from "../shared/StandardIndexCard";
|
import { StandardIndexCard } from "../shared/StandardIndexCard";
|
||||||
import type { CollectionItemRendererProps, CollectionRendererProps } from "../../types/renderer.types";
|
import type {
|
||||||
|
CollectionItemRendererProps,
|
||||||
|
CollectionRendererProps,
|
||||||
|
SearchResultItem,
|
||||||
|
} from "../../types/renderer.types";
|
||||||
|
|
||||||
|
function sortWithExtraPointsAfterDu(items: SearchResultItem[]): SearchResultItem[] {
|
||||||
|
const isExtra = (item: SearchResultItem) => {
|
||||||
|
const name = (asString(item.attributes.name) || item.title || "").toLowerCase();
|
||||||
|
const code = (asString(item.attributes.code) || item.slug || "").toLowerCase();
|
||||||
|
return name.includes("extra") || code.includes("extra");
|
||||||
|
};
|
||||||
|
|
||||||
|
const extraItems = items.filter(isExtra);
|
||||||
|
const regularItems = items.filter((item) => !isExtra(item));
|
||||||
|
|
||||||
|
regularItems.sort((a, b) => {
|
||||||
|
const aOrder =
|
||||||
|
typeof a.attributes.sort_order === "number"
|
||||||
|
? a.attributes.sort_order
|
||||||
|
: 999;
|
||||||
|
const bOrder =
|
||||||
|
typeof b.attributes.sort_order === "number"
|
||||||
|
? b.attributes.sort_order
|
||||||
|
: 999;
|
||||||
|
return aOrder - bOrder;
|
||||||
|
});
|
||||||
|
|
||||||
|
return [...regularItems, ...extraItems];
|
||||||
|
}
|
||||||
|
|
||||||
export function AcuPointIndexCollectionRenderer(props: CollectionRendererProps) {
|
export function AcuPointIndexCollectionRenderer(props: CollectionRendererProps) {
|
||||||
return <CollectionScaffold {...props} />;
|
const sortedItems = useMemo(
|
||||||
|
() => sortWithExtraPointsAfterDu(props.items),
|
||||||
|
[props.items],
|
||||||
|
);
|
||||||
|
return <CollectionScaffold {...props} items={sortedItems} />;
|
||||||
}
|
}
|
||||||
export function AcuPointCollectionRenderer(props: CollectionRendererProps) {
|
export function AcuPointCollectionRenderer(props: CollectionRendererProps) {
|
||||||
return <CollectionScaffold {...props} />;
|
return <CollectionScaffold {...props} />;
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,30 @@ export function CollectionTemplateScreen({
|
||||||
|
|
||||||
const merged = useMemo(() => {
|
const merged = useMemo(() => {
|
||||||
const pages = query.data?.pages ?? [];
|
const pages = query.data?.pages ?? [];
|
||||||
|
const items = pages.flatMap((page) => page.items);
|
||||||
|
if (templateCode === "m0001_ct0002") {
|
||||||
|
const isExtra = (item: (typeof items)[0]) => {
|
||||||
|
const name = (item.attributes?.name ? String(item.attributes.name) : item.title || "").toLowerCase();
|
||||||
|
const code = (item.attributes?.code ? String(item.attributes.code) : item.slug || "").toLowerCase();
|
||||||
|
return name.includes("extra") || code.includes("extra");
|
||||||
|
};
|
||||||
|
const extraItems = items.filter(isExtra);
|
||||||
|
const regularItems = items.filter((item) => !isExtra(item));
|
||||||
|
regularItems.sort((a, b) => {
|
||||||
|
const aOrder = typeof a.attributes?.sort_order === "number" ? (a.attributes.sort_order as number) : 999;
|
||||||
|
const bOrder = typeof b.attributes?.sort_order === "number" ? (b.attributes.sort_order as number) : 999;
|
||||||
|
return aOrder - bOrder;
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
total: pages[0]?.total ?? 0,
|
||||||
|
items: [...regularItems, ...extraItems],
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
total: pages[0]?.total ?? 0,
|
total: pages[0]?.total ?? 0,
|
||||||
items: pages.flatMap((page) => page.items),
|
items,
|
||||||
};
|
};
|
||||||
}, [query.data]);
|
}, [query.data, templateCode]);
|
||||||
|
|
||||||
const collectionRendererCode = contract.presentation.renderers.collection;
|
const collectionRendererCode = contract.presentation.renderers.collection;
|
||||||
const itemRendererCode = contract.presentation.renderers.collection_item;
|
const itemRendererCode = contract.presentation.renderers.collection_item;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue