Skip to content
Snippets Groups Projects
Commit e0e9d6ae authored by Lukas's avatar Lukas
Browse files

Create utility functions for each search section

parent f866591d
No related branches found
No related tags found
1 merge request!494Lbudginas/#392 part1 reduce searches component
import { convertIdsToBooleanArray, getPageUrlParams } from "@/lib/utils";
import { dataToURL } from "@/utils/URLutils";
import Explorer from "@/types/Explorer";
export function startAccountOperationsSearch(
accountOperationsSearchProps: Explorer.AccountSearchOperationsProps,
setLastSearchKey: (val: "account") => void,
setAccountOperationsPage: (val: number | undefined) => void,
setAccountOperationsSearchProps: (
props: Explorer.AccountSearchOperationsProps
) => void,
setPreviousAccountOperationsSearchProps: (
props: Explorer.AccountSearchOperationsProps
) => void
) {
setLastSearchKey("account");
setAccountOperationsPage(undefined);
setAccountOperationsSearchProps(accountOperationsSearchProps);
setPreviousAccountOperationsSearchProps(accountOperationsSearchProps);
}
export function getAccountPageLink(
accountOperationsSearchProps:
| Explorer.AccountSearchOperationsProps
| undefined,
searchRanges: any
): string {
if (!accountOperationsSearchProps) return "#";
const urlParams: Explorer.UrlParam[] = [
{
paramName: "fromBlock",
paramValue: dataToURL(accountOperationsSearchProps.fromBlock),
},
{
paramName: "toBlock",
paramValue: dataToURL(accountOperationsSearchProps.toBlock),
},
{
paramName: "fromDate",
paramValue: dataToURL(accountOperationsSearchProps.startDate),
},
{
paramName: "toDate",
paramValue: dataToURL(accountOperationsSearchProps.endDate),
},
{
paramName: "rangeSelectKey",
paramValue: dataToURL(searchRanges.rangeSelectKey),
},
];
if (accountOperationsSearchProps.operationTypes) {
urlParams.push({
paramName: "filters",
paramValue: dataToURL(
convertIdsToBooleanArray(accountOperationsSearchProps.operationTypes)
),
});
}
if (searchRanges.rangeSelectKey === "lastTime") {
urlParams.push({
paramName: "lastTime",
paramValue: dataToURL(searchRanges.lastTimeUnitValue),
});
urlParams.push({
paramName: "timeUnit",
paramValue: dataToURL(searchRanges.timeUnitSelectKey),
});
}
if (searchRanges.rangeSelectKey === "lastBlocks") {
urlParams.push({
paramName: "lastBlocks",
paramValue: dataToURL(searchRanges.lastBlocksValue),
});
}
return `/@${accountOperationsSearchProps.accountName}${getPageUrlParams(
urlParams
)}`;
}
import { convertIdsToBooleanArray, getPageUrlParams } from "@/lib/utils";
import Explorer from "@/types/Explorer";
import { dataToURL } from "@/utils/URLutils";
export function startBlockSearch(
blockSearchProps: Explorer.BlockSearchProps,
setBlockSearchProps: (props: Explorer.BlockSearchProps) => void,
setLastSearchKey: (val: "block") => void
) {
setBlockSearchProps(blockSearchProps);
setLastSearchKey("block");
}
export function getBlockPageLink(
blockSearchProps: Explorer.BlockSearchProps | undefined,
operationsTypes: any
): (blockNumber: number) => string {
return (blockNumber: number) => {
if (!blockSearchProps) return "#";
const urlParams: Explorer.UrlParam[] = [
{
paramName: "accountName",
paramValue: dataToURL(blockSearchProps.accountName),
},
{
paramName: "keyContent",
paramValue: dataToURL(blockSearchProps.deepProps.content),
},
{
paramName: "setOfKeys",
paramValue: dataToURL(blockSearchProps.deepProps.keys),
},
];
if (blockSearchProps.operationTypes) {
const booleanTypesArray = convertIdsToBooleanArray(
blockSearchProps.operationTypes
);
let isFull = !!blockSearchProps.operationTypes;
operationsTypes?.forEach((operationType: any) => {
if (
!blockSearchProps.operationTypes?.includes(operationType.op_type_id)
)
isFull = false;
});
urlParams.push({
paramName: "filters",
paramValue: dataToURL(!isFull ? booleanTypesArray : []),
});
}
return `/block/${blockNumber}${getPageUrlParams(urlParams)}`;
};
}
import Explorer from "@/types/Explorer";
export function startCommentPermlinkSearch(
commentPermlinkSearchProps: Explorer.CommentPermlinSearchParams,
setPermlinkSearchProps: (props: Explorer.PermlinkSearchProps) => void,
setCommentPaginationPage: (val: number) => void,
setCommentType: (val: "all" | "post" | "comment" | undefined) => void,
setLastSearchKey: (val: "comment-permlink") => void
) {
const { ...params } = commentPermlinkSearchProps;
const props: Explorer.PermlinkSearchProps = {
...params,
accountName: params.accountName || "",
};
setPermlinkSearchProps(props);
setCommentPaginationPage(1);
setCommentType(undefined);
setLastSearchKey("comment-permlink");
}
import {
convertBooleanArrayToIds,
convertIdsToBooleanArray,
getPageUrlParams,
} from "@/lib/utils";
import { dataToURL } from "@/utils/URLutils";
import Explorer from "@/types/Explorer";
export async function startCommentSearch(
commentSearchParams: Explorer.CommentSearchParams,
setCommentSearchProps: (props: Explorer.CommentSearchProps) => void,
setCommentPaginationPage: (page: number) => void,
setPreviousCommentSearchProps: (props: Explorer.CommentSearchProps) => void,
setLastSearchKey: (key: "comment") => void
) {
const { filters, ...params } = commentSearchParams;
const props: Explorer.CommentSearchProps = {
...params,
accountName: params.accountName || "",
operationTypes:
filters && filters.length ? convertBooleanArrayToIds(filters) : undefined,
};
setCommentSearchProps(props);
setCommentPaginationPage(1);
setPreviousCommentSearchProps(props);
setLastSearchKey("comment");
}
export function getCommentPageLink(
commentSearchProps: Explorer.CommentSearchProps | undefined,
searchRanges: any
): string {
if (!commentSearchProps) return "#";
const urlParams: Explorer.UrlParam[] = [
{
paramName: "fromBlock",
paramValue: dataToURL(commentSearchProps.fromBlock),
},
{ paramName: "toBlock", paramValue: dataToURL(commentSearchProps.toBlock) },
{
paramName: "rangeSelectKey",
paramValue: dataToURL(searchRanges.rangeSelectKey),
},
{
paramName: "lastTime",
paramValue: dataToURL(searchRanges.lastTimeUnitValue),
},
{
paramName: "lastBlocks",
paramValue: dataToURL(searchRanges.lastBlocksValue),
},
{
paramName: "timeUnit",
paramValue: dataToURL(searchRanges.timeUnitSelectKey),
},
{
paramName: "permlink",
paramValue: dataToURL(commentSearchProps.permlink),
},
];
if (commentSearchProps.operationTypes) {
urlParams.push({
paramName: "filters",
paramValue: dataToURL(
convertIdsToBooleanArray(commentSearchProps.operationTypes)
),
});
}
return `/comments/@${dataToURL(
commentSearchProps.accountName
)}${getPageUrlParams(urlParams)}`;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment