nicolium: Migrate data exporter to hooks

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-03-14 14:15:27 +01:00
parent 9f3458cf41
commit a88e070acb
2 changed files with 12 additions and 15 deletions

View File

@ -1,10 +1,8 @@
import { defineMessages } from 'react-intl';
import { getClient } from '@/api';
import { useAuthStore } from '@/stores/auth';
import toast from '@/toast';
import type { Account, PaginatedResponse } from 'pl-api';
import type { Account, PaginatedResponse, PlApiClient } from 'pl-api';
const messages = defineMessages({
blocksSuccess: {
@ -41,11 +39,8 @@ const listAccounts = async (response: PaginatedResponse<Account>) => {
return Array.from(new Set(accounts));
};
const exportFollows = async () => {
const me = useAuthStore.getState().currentAccountId;
if (!me) return;
const response = await getClient().accounts.getAccountFollowing(me, { limit: 40 });
const exportFollows = async (client: PlApiClient) => {
const response = await client.accounts.getAccountFollowing(me, { limit: 40 });
const followings = await listAccounts(response);
const followingsCsv = followings.map((fqn) => fqn + ',true');
followingsCsv.unshift('Account address,Show boosts');
@ -54,16 +49,16 @@ const exportFollows = async () => {
toast.success(messages.followersSuccess);
};
const exportBlocks = async () => {
const response = await getClient().filtering.getBlocks({ limit: 40 });
const exportBlocks = async (client: PlApiClient) => {
const response = await client.filtering.getBlocks({ limit: 40 });
const blocks = await listAccounts(response);
fileExport(blocks.join('\n'), 'export_block.csv');
toast.success(messages.blocksSuccess);
};
const exportMutes = async () => {
const response = await getClient().filtering.getMutes({ limit: 40 });
const exportMutes = async (client: PlApiClient) => {
const response = await client.filtering.getMutes({ limit: 40 });
const mutes = await listAccounts(response);
fileExport(mutes.join('\n'), 'export_mutes.csv');

View File

@ -7,6 +7,7 @@ import Column from '@/components/ui/column';
import Form from '@/components/ui/form';
import FormActions from '@/components/ui/form-actions';
import Text from '@/components/ui/text';
import { useClient } from '@/hooks/use-client';
interface ICSVExporter {
inputLabel: React.ReactNode;
@ -51,12 +52,13 @@ const messages = defineMessages({
});
const ExportDataPage = () => {
const client = useClient();
const intl = useIntl();
return (
<Column label={intl.formatMessage(messages.heading)}>
<CSVExporter
action={exportFollows}
action={() => exportFollows(client)}
inputLabel={<FormattedMessage id='export_data.follows_label' defaultMessage='Follows' />}
inputHint={
<FormattedMessage
@ -72,7 +74,7 @@ const ExportDataPage = () => {
}
/>
<CSVExporter
action={exportBlocks}
action={() => exportBlocks(client)}
inputLabel={<FormattedMessage id='export_data.blocks_label' defaultMessage='Blocks' />}
inputHint={
<FormattedMessage
@ -85,7 +87,7 @@ const ExportDataPage = () => {
}
/>
<CSVExporter
action={exportMutes}
action={() => exportMutes(client)}
inputLabel={<FormattedMessage id='export_data.mutes_label' defaultMessage='Mutes' />}
inputHint={
<FormattedMessage