Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add es-toolkit, remove radashi #1675

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default tseslint.config(
},
],

"no-empty-function": "warn",
"no-nested-ternary": "warn",
"no-unreachable": "warn",
"linebreak-style": ["warn", "unix"],
Expand All @@ -83,12 +84,6 @@ export default tseslint.config(
selector: "TSEnumDeclaration",
message: "Don't declare enums",
},
{
// https://github.com/eslint/eslint/issues/19105#issuecomment-2458833155
selector:
"ImportDeclaration[source.value='radashi'][specifiers.length=0], ImportDeclaration[source.value='radashi'] > :matches(ImportSpecifier, ImportDefaultSpecifier)",
message: "Use only `import * as _ from 'radashi'`",
},
],
"no-restricted-imports": [
"warn",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"date-fns": "^4.1.0",
"dexie": "^4.0.9",
"dexie-export-import": "^4.1.2",
"es-toolkit": "^1.26.1",
"history": "^4.10.1",
"ionicons": "^7.4.0",
"lemmy-js-client": "0.20.0-alpha.17",
Expand All @@ -91,7 +92,6 @@
"micromark-util-combine-extensions": "^2.0.0",
"modern-screenshot": "^4.5.1",
"photoswipe": "^5.4.4",
"radashi": "^12.2.0",
"react": "0.0.0-experimental-5c56b873-20241107",
"react-animate-height": "^3.2.3",
"react-dom": "0.0.0-experimental-5c56b873-20241107",
Expand Down
17 changes: 8 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/core/GlobalStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
useLayoutEffect,
} from "react";

import { initialState as initialSettingsState } from "#/features/settings/settingsSlice";
import { getLocalStorageInitialState } from "#/features/settings/settingsSlice";
import { isNative } from "#/helpers/device";
import useSystemDarkMode, {
DARK_MEDIA_SELECTOR,
Expand Down Expand Up @@ -65,13 +65,15 @@ function updateDocumentTheme(
}
}

const localStorageInitialState = getLocalStorageInitialState();

// Prevent flash of white content and repaint before react component setup
updateDocumentTheme(
initialSettingsState.appearance.dark.usingSystemDarkMode
localStorageInitialState.appearance.dark.usingSystemDarkMode
? window.matchMedia(DARK_MEDIA_SELECTOR).matches
: initialSettingsState.appearance.dark.userDarkMode,
initialSettingsState.appearance.dark.pureBlack,
initialSettingsState.appearance.theme,
: localStorageInitialState.appearance.dark.userDarkMode,
localStorageInitialState.appearance.dark.pureBlack,
localStorageInitialState.appearance.theme,
);

const fixedDeviceFontCss = css`
Expand Down
12 changes: 1 addition & 11 deletions src/features/auth/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
IonToolbar,
} from "@ionic/react";
import { add } from "ionicons/icons";
import * as _ from "radashi";
import { useContext, useEffect, useState } from "react";

import AppHeader from "#/features/shared/AppHeader";
Expand Down Expand Up @@ -127,22 +126,13 @@ function AccountSwitcherContents({
<IonRadioGroup
value={selectedAccount}
onIonChange={async (e) => {
const selectAccountPromise = onSelectAccount(e.target.value);

// Early return against loading state
if (!_.isPromise(selectAccountPromise)) {
setSelectedAccount(e.target.value);
onDismiss();
return;
}

setLoading(true);

const old = selectedAccount;
setSelectedAccount(e.target.value);

try {
await selectAccountPromise;
await onSelectAccount(e.target.value);
} catch (error) {
setSelectedAccount(old);
throw error;
Expand Down
3 changes: 2 additions & 1 deletion src/features/auth/AppContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useIonViewDidEnter } from "@ionic/react";
import { noop } from "es-toolkit";
import React, {
RefObject,
createContext,
Expand All @@ -18,7 +19,7 @@ interface IAppContext {

export const AppContext = createContext<IAppContext>({
activePageRef: undefined,
setActivePage: () => {},
setActivePage: noop,
});

export function AppContextProvider({ children }: React.PropsWithChildren) {
Expand Down
19 changes: 10 additions & 9 deletions src/features/auth/PageContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useIonModal } from "@ionic/react";
import { css } from "@linaria/core";
import { noop } from "es-toolkit";
import {
Comment,
CommentView,
Expand Down Expand Up @@ -104,15 +105,15 @@ export const PageContext = createContext<IPageContext>({
presentCommentEdit: async () => undefined,
presentCommentReply: async () => undefined,
presentPrivateMessageCompose: async () => undefined,
presentReport: () => {},
presentPostEditor: () => {},
presentSelectText: () => {},
presentShareAsImage: () => {},
presentAccountSwitcher: () => {},
presentBanUser: () => {},
presentCreateCrosspost: () => {},
presentUserTag: () => {},
presentDatabaseErrorModal: () => {},
presentReport: noop,
presentPostEditor: noop,
presentSelectText: noop,
presentShareAsImage: noop,
presentAccountSwitcher: noop,
presentBanUser: noop,
presentCreateCrosspost: noop,
presentUserTag: noop,
presentDatabaseErrorModal: noop,
});

interface PageContextProvider extends React.PropsWithChildren {
Expand Down
4 changes: 2 additions & 2 deletions src/features/auth/authSlice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import { ApplicationContext } from "capacitor-application-context";
import { uniqBy } from "es-toolkit";
import { Register } from "lemmy-js-client";
import * as _ from "radashi";

import { resetComments } from "#/features/comment/commentSlice";
import { resetCommunities } from "#/features/community/communitySlice";
Expand Down Expand Up @@ -87,7 +87,7 @@ export const authSlice = createSlice({
);
}

const accounts = _.unique(
const accounts = uniqBy(
[action.payload, ...cleanedPreviousAccounts],
(c) => c.handle,
);
Expand Down
6 changes: 3 additions & 3 deletions src/features/auth/login/data/servers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from "radashi";
import { uniq } from "es-toolkit";

/**
* 🚨 Want to add a server to this list?
Expand Down Expand Up @@ -96,7 +96,7 @@ export const SERVERS_BY_CATEGORY = {
furry: ["pawb.social", "yiffit.net"],
};

export const WHITELISTED_SERVERS = _.unique(
export const WHITELISTED_SERVERS = uniq(
Object.values(SERVERS_BY_CATEGORY).flat(),
);

Expand All @@ -109,7 +109,7 @@ const ADDITIONAL_LOGIN_INSTANCES = [
"lemmy.myserv.one",
];

export const LOGIN_SERVERS = _.unique([
export const LOGIN_SERVERS = uniq([
...WHITELISTED_SERVERS,
...ADDITIONAL_LOGIN_INSTANCES,
]);
Expand Down
4 changes: 2 additions & 2 deletions src/features/auth/login/join/Join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
IonToggle,
IonToolbar,
} from "@ionic/react";
import { startCase } from "es-toolkit";
import { LoginResponse } from "lemmy-js-client";
import * as _ from "radashi";
import { useContext, useEffect, useRef, useState } from "react";

import AppHeader from "#/features/shared/AppHeader";
Expand Down Expand Up @@ -85,7 +85,7 @@ export default function Join({ answer }: JoinProps) {
if (!(error instanceof Error)) throw error;

presentToast({
message: `Registration error: ${_.title(error.message)}`,
message: `Registration error: ${startCase(error.message)}`,
color: "danger",
position: "top",
fullscreen: true,
Expand Down
4 changes: 2 additions & 2 deletions src/features/auth/login/login/PickLoginServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
IonToolbar,
} from "@ionic/react";
import { styled } from "@linaria/react";
import { uniq } from "es-toolkit";
import { GetSiteResponse } from "lemmy-js-client";
import * as _ from "radashi";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { VList, VListHandle } from "virtua";

Expand Down Expand Up @@ -50,7 +50,7 @@ export default function PickLoginServer() {
const searchHostname = stripProtocol(search.trim());
const instances = useMemo(
() =>
_.unique([...getCustomServers(), ...LOGIN_SERVERS]).filter((server) =>
uniq([...getCustomServers(), ...LOGIN_SERVERS]).filter((server) =>
server.includes(searchHostname.toLowerCase()),
),
[searchHostname],
Expand Down
6 changes: 3 additions & 3 deletions src/features/auth/login/pickJoinServer/PickJoinServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import {
} from "@ionic/react";
import { css } from "@linaria/core";
import { styled } from "@linaria/react";
import { compact, uniqBy } from "es-toolkit";
import {
ellipsisHorizontalCircleOutline,
ellipsisVertical,
} from "ionicons/icons";
import { GetSiteResponse } from "lemmy-js-client";
import * as _ from "radashi";
import {
useCallback,
useContext,
Expand Down Expand Up @@ -158,7 +158,7 @@ export default function PickJoinServer() {
? [normalize(customInstance), ...matches]
: matches;

return _.unique(all, ({ url }) => url);
return uniqBy(all, ({ url }) => url);
}, [customInstance, matchingInstances, category]);

const customSearchHostnameInvalid = useMemo(
Expand Down Expand Up @@ -242,7 +242,7 @@ export default function PickJoinServer() {
);

presentActionSheet({
buttons: _.sift([
buttons: compact([
{
text: `Join ${selectedUrl}`,
handler: () => {
Expand Down
4 changes: 2 additions & 2 deletions src/features/comment/CommentLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import spoiler from "@aeharding/remark-lemmy-spoiler";
import { styled } from "@linaria/react";
import { uniqBy } from "es-toolkit";
import { Text } from "mdast";
import * as _ from "radashi";
import { useMemo } from "react";
import { defaultUrlTransform } from "react-markdown";
import remarkParse from "remark-parse";
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function CommentLinks({ markdown }: CommentLinksProps) {
});

// Dedupe by url
links = _.unique(links, (l) => l.url);
links = uniqBy(links, ({ url }) => url);

// e.g. `http://127.0.0.1:8080”`
links = links.filter(({ url }) => defaultUrlTransform(url));
Expand Down
4 changes: 2 additions & 2 deletions src/features/comment/CommentSort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IonIcon,
} from "@ionic/react";
import { OverlayEventDetail } from "@ionic/react/dist/types/components/react-component-lib/interfaces";
import { startCase } from "es-toolkit";
import {
arrowUpCircleOutline,
flameOutline,
Expand All @@ -14,7 +15,6 @@ import {
timeOutline,
} from "ionicons/icons";
import { CommentSortType } from "lemmy-js-client";
import * as _ from "radashi";
import { useContext, useState } from "react";

import { AppContext } from "#/features/auth/AppContext";
Expand All @@ -30,7 +30,7 @@ export const COMMENT_SORTS = [

const BUTTONS: ActionSheetButton<CommentSortType>[] = COMMENT_SORTS.map(
(sortType) => ({
text: _.title(sortType),
text: startCase(sortType),
data: sortType,
icon: getSortIcon(sortType),
}),
Expand Down
Loading