pl-hooks: Work on making this an actual library

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-10-17 23:55:52 +02:00
parent a4b520a13a
commit fb34a8bf4a
59 changed files with 82 additions and 76 deletions

View file

@ -1,5 +1,5 @@
import { PLEROMA, type UpdateNotificationSettingsParams, type Account, type CreateAccountParams, type PaginatedResponse, type Relationship } from 'pl-api';
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient, type PlfeResponse } from 'pl-fe/api';
import { Entities } from 'pl-fe/entity-store/entities';

View file

@ -1,5 +1,5 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { fetchRelationships } from 'pl-fe/actions/accounts';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { defineMessages } from 'react-intl';
import { getClient } from 'pl-fe/api';

View file

@ -7,7 +7,7 @@
* @see module:pl-fe/actions/security
*/
import { credentialAccountSchema, PlApiClient, type CreateAccountParams, type Token } from 'pl-api';
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { defineMessages } from 'react-intl';
import * as v from 'valibot';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';

View file

@ -1,5 +1,5 @@
import throttle from 'lodash/throttle';
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { defineMessages, IntlShape } from 'react-intl';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { isLoggedIn } from 'pl-fe/utils/auth';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { isLoggedIn } from 'pl-fe/utils/auth';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { defineMessages } from 'react-intl';
import { STATUS_FETCH_SOURCE_FAIL, STATUS_FETCH_SOURCE_REQUEST, STATUS_FETCH_SOURCE_SUCCESS } from 'pl-fe/actions/statuses';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { AppDispatch, RootState } from 'pl-fe/store';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { isLoggedIn } from 'pl-fe/utils/auth';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { defineMessages } from 'react-intl';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { selectAccount } from 'pl-fe/selectors';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { selectAccount } from 'pl-fe/selectors';

View file

@ -1,6 +1,6 @@
import IntlMessageFormat from 'intl-messageformat';
import 'intl-pluralrules';
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { defineMessages } from 'react-intl';
import { FILTER_TYPES, type FilterType } from 'pl-fe/features/notifications';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { isLoggedIn } from 'pl-fe/utils/auth';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';

View file

@ -1,5 +1,5 @@
import mapValues from 'lodash/mapValues';
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { verifyCredentials } from './auth';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { useSettingsStore } from 'pl-fe/stores';

View file

@ -1,4 +1,3 @@
import { Account } from 'pl-hooks/normalizers/normalizeAccount';
import { defineMessage } from 'react-intl';
import { patchMe } from 'pl-fe/actions/me';
@ -11,6 +10,7 @@ import toast from 'pl-fe/toast';
import { isLoggedIn } from 'pl-fe/utils/auth';
import type { AppDispatch, RootState } from 'pl-fe/store';
import type { Account } from 'pl-hooks/normalizers/normalizeAccount';
const FE_NAME = 'pl_fe';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';
import { useModalsStore, useSettingsStore } from 'pl-fe/stores';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';

View file

@ -1,5 +1,5 @@
import { Map as ImmutableMap } from 'immutable';
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getLocale } from 'pl-fe/actions/settings';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { getClient } from 'pl-fe/api';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { HStack, Icon, Text } from 'pl-fe/components/ui';

View file

@ -1,5 +1,5 @@
import clsx from 'clsx';
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useEffect, useRef } from 'react';
import { defineMessages, useIntl, FormattedList, FormattedMessage } from 'react-intl';
import { Link, useHistory } from 'react-router-dom';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import Status, { IStatus } from 'pl-fe/components/status';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { FormattedMessage } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { FormattedList, FormattedMessage } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { cancelQuoteCompose } from 'pl-fe/actions/compose';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { cancelReplyCompose } from 'pl-fe/actions/compose';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useEffect } from 'react';
import { useHistory } from 'react-router-dom';

View file

@ -1,5 +1,5 @@
import { List as ImmutableList, OrderedSet as ImmutableOrderedSet } from 'immutable';
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useEffect, useRef, useState } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useCallback } from 'react';
import { FormattedDate, FormattedMessage } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import ReactSwipeableViews from 'react-swipeable-views';

View file

@ -1,4 +1,4 @@
import { useNotification } from 'pl-hooks/hooks/notifications/useNotification';
import { useNotification } from 'pl-hooks';
import React, { useCallback } from 'react';
import { defineMessages, useIntl, FormattedList, FormattedMessage, IntlShape, MessageDescriptor } from 'react-intl';
import { Link, useHistory } from 'react-router-dom';

View file

@ -1,8 +1,6 @@
import clsx from 'clsx';
import debounce from 'lodash/debounce';
import { useMarker } from 'pl-hooks/hooks/markers/useMarkers';
import { useUpdateMarkerMutation } from 'pl-hooks/hooks/markers/useUpdateMarkerMutation';
import { useNotificationList } from 'pl-hooks/hooks/notifications/useNotificationList';
import { useMarker, useNotificationList, useUpdateMarkerMutation } from 'pl-hooks';
import React, { useCallback, useEffect, useRef } from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import QuotedStatus from 'pl-fe/components/quoted-status';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useEffect } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { Redirect } from 'react-router-dom';

View file

@ -1,4 +1,4 @@
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import React from 'react';
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';

View file

@ -1,5 +1,5 @@
import L from 'leaflet';
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useEffect, useRef } from 'react';
import { FormattedMessage } from 'react-intl';

View file

@ -1,5 +1,5 @@
import clsx from 'clsx';
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useEffect, useState } from 'react';
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useEffect, useRef } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { FormattedMessage } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';

View file

@ -1,6 +1,5 @@
import clsx from 'clsx';
import { prefetchMarker } from 'pl-hooks/hooks/markers/useMarkers';
import { prefetchNotifications } from 'pl-hooks/hooks/notifications/useNotificationList';
import { prefetchMarker, prefetchNotifications } from 'pl-hooks';
import React, { Suspense, lazy, useEffect, useRef } from 'react';
import { Switch, useHistory, useLocation, Redirect } from 'react-router-dom';

View file

@ -1,4 +1,4 @@
import { useStatus } from 'pl-hooks/hooks/statuses/useStatus';
import { useStatus } from 'pl-hooks';
import React from 'react';
import { Helmet } from 'react-helmet-async';
import { FormattedMessage } from 'react-intl';

View file

@ -1,7 +1,7 @@
import { InfiniteData, keepPreviousData, useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query';
import sumBy from 'lodash/sumBy';
import { type Chat, type ChatMessage as BaseChatMessage, type PaginatedResponse, chatMessageSchema, type Relationship } from 'pl-api';
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import * as v from 'valibot';
import { ChatWidgetScreens, useChatContext } from 'pl-fe/contexts/chat-context';

View file

@ -1,5 +1,5 @@
import { useMutation, keepPreviousData, useQuery } from '@tanstack/react-query';
import { importEntities } from 'pl-hooks/importer';
import { importEntities } from 'pl-hooks';
import { fetchRelationships } from 'pl-fe/actions/accounts';
import { useAppDispatch, useClient } from 'pl-fe/hooks';

View file

@ -0,0 +1,12 @@
export * from './contexts/api-client';
export * from './contexts/query-client';
export * from './hooks/accounts/useAccount';
export * from './hooks/accounts/useAccountRelationship';
export * from './hooks/markers/useMarkers';
export * from './hooks/markers/useUpdateMarkerMutation';
export * from './hooks/notifications/useNotification';
export * from './hooks/notifications/useNotificationList';
export * from './hooks/statuses/useStatus';
export * from './importer';

View file

@ -1,9 +1,5 @@
/**
* Status normalizer:
* Converts API statuses into our internal format.
* @see {@link https://docs.joinmastodon.org/entities/status/}
*/
import { type Account as BaseAccount, type Status as BaseStatus, type MediaAttachment, mentionSchema } from 'pl-api';
import * as v from 'valibot';
type StatusApprovalStatus = Exclude<BaseStatus['approval_status'], null>;
type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct' | 'group' | 'mutuals_only' | 'local';
@ -23,7 +19,7 @@ const normalizeStatus = ({ account, accounts, reblog, poll, group, quote, ...sta
const hasSelfMention = status.mentions.some(mention => account.id === mention.id);
if (isSelfReply && !hasSelfMention) {
const selfMention = mentionSchema.parse(account);
const selfMention = v.parse(mentionSchema, account);
mentions = [selfMention, ...mentions];
}

View file

@ -35,8 +35,9 @@
"dependencies": {
"@tanstack/react-query": "^5.56.2",
"lodash": "^4.17.21",
"pl-api": "^0.0.37",
"react": "^18.3.1"
"pl-api": "^0.1.1",
"react": "^18.3.1",
"valibot": "^0.42.1"
},
"module": "./dist/main.es.js",
"types": "dist/main.d.ts",

View file

@ -2138,10 +2138,10 @@ pkg-types@^1.0.3, pkg-types@^1.1.1:
mlly "^1.7.1"
pathe "^1.1.2"
pl-api@^0.0.37:
version "0.0.37"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.37.tgz#1475be139a3733b8a60dc3dd5fdfb00f83743eea"
integrity sha512-oCeKkJtUYC5XwM5PIVt+VPdLrJT7rjvfXgiv+qrUydK++cHnO1ZiixCaBnYW3M5D1BLZ6/OS4T+mk5hlCt8+1g==
pl-api@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.1.1.tgz#e3465482697ea53e10bba510c5217c42b1d40ab0"
integrity sha512-JFao273dOG9XgrunqlfJn+e3DUr001MePCmJasQwaX3aPjM/L158hKfCnYPmoDKn1u5bfekMK6tVauBtbnkmqA==
dependencies:
blurhash "^2.0.5"
http-link-header "^1.1.3"
@ -2149,7 +2149,7 @@ pl-api@^0.0.37:
object-to-formdata "^4.5.1"
query-string "^9.1.0"
semver "^7.6.3"
zod "^3.23.8"
valibot "^0.42.1"
possible-typed-array-names@^1.0.0:
version "1.0.0"
@ -2586,6 +2586,11 @@ uri-js@^4.2.2, uri-js@^4.4.1:
dependencies:
punycode "^2.1.0"
valibot@^0.42.1:
version "0.42.1"
resolved "https://registry.yarnpkg.com/valibot/-/valibot-0.42.1.tgz#a31183d8e9d7552f98e22ca0977172cab8815188"
integrity sha512-3keXV29Ar5b//Hqi4MbSdV7lfVp6zuYLZuA9V1PvQUsXqogr+u5lvLPLk3A4f74VUXDnf/JfWMN6sB+koJ/FFw==
vite-plugin-dts@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/vite-plugin-dts/-/vite-plugin-dts-4.2.1.tgz#f8bee33b732929717ce13ef7a382696d51200c30"
@ -2665,8 +2670,3 @@ yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
zod@^3.23.8:
version "3.23.8"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.23.8.tgz#e37b957b5d52079769fb8097099b592f0ef4067d"
integrity sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==