Merge pull request 'fix(m0001_ct0002): ensure Extra Points is displayed at the end after Du Channel' (#92) from Points into main
Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-mobile-ui/pulls/92 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
4e6b8ec8ee
|
|
@ -1,12 +1,45 @@
|
|||
import React from "react";
|
||||
import React, { useMemo } from "react";
|
||||
import { Pressable, Text, View } from "react-native";
|
||||
import { asNumber, asString, asStringArray } from "../helpers/value";
|
||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||
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) {
|
||||
return <CollectionScaffold {...props} />;
|
||||
const sortedItems = useMemo(
|
||||
() => sortWithExtraPointsAfterDu(props.items),
|
||||
[props.items],
|
||||
);
|
||||
return <CollectionScaffold {...props} items={sortedItems} />;
|
||||
}
|
||||
export function MeridianCollectionRenderer(props: CollectionRendererProps) {
|
||||
return <CollectionScaffold {...props} />;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,44 @@
|
|||
import React from "react";
|
||||
import React, { useMemo } from "react";
|
||||
import { asString } from "../helpers/value";
|
||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||
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) {
|
||||
return <CollectionScaffold {...props} />;
|
||||
const sortedItems = useMemo(
|
||||
() => sortWithExtraPointsAfterDu(props.items),
|
||||
[props.items],
|
||||
);
|
||||
return <CollectionScaffold {...props} items={sortedItems} />;
|
||||
}
|
||||
export function AcuPointCollectionRenderer(props: CollectionRendererProps) {
|
||||
return <CollectionScaffold {...props} />;
|
||||
|
|
|
|||
|
|
@ -57,11 +57,30 @@ export function CollectionTemplateScreen({
|
|||
|
||||
const merged = useMemo(() => {
|
||||
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 {
|
||||
total: pages[0]?.total ?? 0,
|
||||
items: pages.flatMap((page) => page.items),
|
||||
items,
|
||||
};
|
||||
}, [query.data]);
|
||||
}, [query.data, templateCode]);
|
||||
|
||||
const collectionRendererCode = contract.presentation.renderers.collection;
|
||||
const itemRendererCode = contract.presentation.renderers.collection_item;
|
||||
|
|
|
|||
Loading…
Reference in New Issue