Skip to content

Commit

Permalink
Merge branch 'revoltchat:main' into fix-linebreak-behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDotJS authored Oct 30, 2024
2 parents 7dca515 + d560836 commit 04ebf9e
Show file tree
Hide file tree
Showing 64 changed files with 8,415 additions and 5,207 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"FunctionExpression": true
}
}
]
],
"solid/jsx-no-undef": ["ignore"]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
.env*
!.env.example
.vercel
.idea
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"test:browser:install": "pnpm --filter browser-test-runner exec playwright install",
"test:browser:regression": "pnpm --filter browser-test-runner exec playwright test regression",
"test:browser:report": "pnpm --filter browser-test-runner exec playwright show-report",
"lint": "eslint --ext .ts,.tsx components/ packages/",
"lint:fix": "pnpm lint --fix",
"lint": "eslint --ext .ts,.tsx packages/client",
"lint:fix": "eslint --fix --ext .ts,.tsx packages/client",
"dev:web": "pnpm --filter client dev",
"dev:desktop": "pnpm --filter desktop tauri dev",
"build:deps": "pnpm --filter revolt.js build",
Expand All @@ -21,6 +21,9 @@
"fmt:check": "prettier --check '**/*.{ts,tsx,json}'",
"typecheck": "cd packages/client && pnpm run typecheck"
},
"devDependencies": {
"eslint": "^8.49.0"
},
"keywords": [],
"engines": {
"node": ">=16",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/codegen.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const directiveRegex = new RegExp("use:(" + DIRECTIVES.join("|") + ")");
export default function codegenPlugin() {
return {
name: "codegen",
enforce: "pre",
enforce: "pre" as const,
transform(src: string, id: string) {
if (fileRegex.test(id)) {
src = src.replace(codegenRegex, (substring, group1) => {
Expand Down
19 changes: 12 additions & 7 deletions packages/client/components/app/interface/channels/text/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function Message(props: Props) {
}
avatar={
<AvatarContainer
// @ts-expect-error this is a hack; replace with plain element & panda-css
use:floating={floatingUserMenusFromMessage(props.message)}
>
<Avatar size={36} src={props.message.avatarURL} />
Expand Down Expand Up @@ -163,12 +164,14 @@ export function Message(props: Props) {
</Tooltip>
</Match>
<Match when={props.message.webhook}>
<Tooltip content={t("app.main.channel.webhook")} placement="top">
<MdCloud {...iconSize(16)} />
</Tooltip>
</Match>
<Match when={props.message.webhook}>
<Tooltip content={t("app.main.channel.webhook")} placement="top">
<Tooltip
content={
"Webhook"

// TODO: missing i18n
}
placement="top"
>
<MdCloud {...iconSize(16)} />
</Tooltip>
</Match>
Expand Down Expand Up @@ -253,7 +256,9 @@ export function Message(props: Props) {
</For>
</Show>
<Reactions
reactions={props.message.reactions}
reactions={
props.message.reactions as never as Map<string, Set<string>>
}
interactions={props.message.interactions}
userId={client().user!.id}
addReaction={react}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const Config: SettingsConfiguration<Channel> = {
return webhook!.name;
}

return t(`app.settings.channel_pages.${key.replaceAll("/", ".")}.title`);
return t(
`app.settings.channel_pages.${key.replaceAll("/", ".")}.title` as any
);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Config: SettingsConfiguration<Server> = {
title(key) {
const t = useTranslation();
return t(
`app.settings.server_pages.${key.replaceAll("/", ".")}.title`,
`app.settings.server_pages.${key.replaceAll("/", ".")}.title` as any,
undefined,
key
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Accessor,
type Accessor,
Match,
Show,
Switch,
Expand Down Expand Up @@ -41,7 +41,7 @@ import MdVerifiedUser from "@material-design-icons/svg/outlined/verified_user.sv

import { useSettingsNavigation } from "../Settings";

import { UserSummary } from "./account";
import { UserSummary } from "./account/index";

/**
* Account Page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default function Keybinds() {

const translateCombo = (combo: KeyCombo, short: boolean) =>
combo
.map((key) => t(`keys.${key}.${short ? "short" : "full"}`, {}, key))
.map((key) =>
t(`keys.${key}.${short ? "short" : "full"}` as any, {}, key)
)
.join("+");

const translateSequence = (sequence: KeyComboSequence, short: boolean) =>
Expand Down Expand Up @@ -94,8 +96,12 @@ export default function Keybinds() {
.flat()
.map((action) => [
action,
t(`app.settings.pages.keybinds.action.${action}.description`) as string,
t(`app.settings.pages.keybinds.action.${action}.title`) as string,
t(
`app.settings.pages.keybinds.action.${action}.description` as any
) as string,
t(
`app.settings.pages.keybinds.action.${action}.title` as any
) as string,
...state.keybinds
.getKeybinds()
[action].flatMap((sequence) => [
Expand Down Expand Up @@ -135,7 +141,7 @@ export default function Keybinds() {
<For each={filteredData()}>
{([category, actions]) => (
<CategoryCollapse
title={t(`app.settings.pages.keybinds.category.${category}`)}
title={t(`app.settings.pages.keybinds.category.${category}` as any)}
// TODO: open={category !== "advanced"}
>
<Column group="6px">
Expand All @@ -144,12 +150,14 @@ export default function Keybinds() {
<ActionCategory>
<CategoryButton
description={t(
`app.settings.pages.keybinds.action.${action}.description`
`app.settings.pages.keybinds.action.${action}.description` as any
)}
action={<BiSolidPlusCircle size={24} />}
onClick={() => addKeybind(action)}
>
{t(`app.settings.pages.keybinds.action.${action}.title`)}
{t(
`app.settings.pages.keybinds.action.${action}.title` as any
)}
</CategoryButton>
<For each={state.keybinds.getKeybinds()[action]}>
{(sequence, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Languages,
browserPreferredLanguage,
language,
loadAndSetLanguage,
setLanguage,
useTranslation,
} from "@revolt/i18n";
import { UnicodeEmoji } from "@revolt/markdown/emoji";
Expand Down Expand Up @@ -101,7 +101,7 @@ function PickLanguage() {
<CategoryButton
icon={<UnicodeEmoji emoji={lang.emoji} />}
action={<Checkbox value={id === language()} />}
onClick={() => loadAndSetLanguage(id as never)}
onClick={() => setLanguage(id as never)}
>
<Row>
{lang.display}{" "}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MdPublic from "@material-design-icons/svg/outlined/public.svg?component-s
import MdToken from "@material-design-icons/svg/outlined/token.svg?component-solid";

import { useSettingsNavigation } from "../../Settings";
import { UserSummary } from "../account";
import { UserSummary } from "../account/index";
import { EditProfileButtons } from "../profile/EditProfileButtons";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const Config: SettingsConfiguration<{ server: Server }> = {
}

return t(
`app.settings.pages.${key.replaceAll("/", ".")}.title`,
`app.settings.pages.${key.replaceAll("/", ".")}.title` as any,
undefined,
key
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

import MdGroups from "@material-design-icons/svg/outlined/groups.svg?component-solid";

import { UserSummary } from "../account";
import { UserSummary } from "../account/index";

import { EditProfileButtons } from "./EditProfileButtons";

Expand Down
1 change: 0 additions & 1 deletion packages/client/components/auth/src/AuthPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import MdDarkMode from "@material-design-icons/svg/filled/dark_mode.svg?componen

import background from "./background.jpg";
import { FlowBase } from "./flows/Flow";

/**
* Authentication page layout
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/client/components/auth/src/flows/FlowVerify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function FlowVerify() {
<FlowTitle>{t("login.error.verify")}</FlowTitle>
<Typography variant="legacy-settings-description">
{t(
`error.${(state() as State & { state: "error" }).error}`,
`error.${(state() as State & { state: "error" }).error}` as any,
undefined,
(state() as State & { state: "error" }).error
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/components/auth/src/flows/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function Form(props: Props) {
{props.children}
<Show when={error()}>
<Typography variant="legacy-settings-description">
{t(`error.${error()}`, undefined, error())}
{t(`error.${error()}` as any, undefined, error())}
</Typography>
</Show>
</Column>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createMemo, createResource } from "solid-js";

import * as i18n from "@solid-primitives/i18n";
import { render, screen } from "@solidjs/testing-library";
import { describe, expect, it } from "vitest";

import { I18nContext, default as i18n, useTranslation } from "..";
import { I18nContext, dict, fetchLanguage, language, useTranslation } from "..";

const TranslatedText = () => {
const t = useTranslation();
Expand All @@ -11,8 +14,16 @@ const TranslatedText = () => {

describe("Translation component", () => {
it("should translate the text", () => {
const [dictionary] = createResource(language, fetchLanguage, {
initialValue: i18n.flatten(dict.en),
});

const t = createMemo(() =>
i18n.translator(dictionary, i18n.resolveTemplate)
);

render(() => (
<I18nContext.Provider value={i18n}>
<I18nContext.Provider value={t()}>
<TranslatedText />
</I18nContext.Provider>
));
Expand Down
47 changes: 24 additions & 23 deletions packages/client/components/i18n/index.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
import { createSignal } from "solid-js";

import { createI18nContext, useI18n } from "@solid-primitives/i18n";
import defaultsDeep from "lodash.defaultsdeep";
import { createContext, createSignal, useContext, useTransition } from "solid-js";
import * as i18n from '@solid-primitives/i18n';

import { Language, Languages } from "./locales/Languages";
import en from "./locales/en.json";

export { Language, Languages } from "./locales/Languages";
export { I18nContext, useI18n } from "@solid-primitives/i18n";
export * from "./dayjs";

/**
* Default dictionary object
*/
const dict = {
export const dict = {
en,
};

export type RawDictionary = typeof dict.en;
export type Dictionary = i18n.Flatten<RawDictionary>;

/**
* Currently set language
*/
const [language, setLanguage] = createSignal<Language>("en" as Language);
const [language, _setLanguage] = createSignal<Language>("en" as Language);
export { language };

/**
* i18n Context
*/
const context = createI18nContext(dict, "en");
export default context;

/**
* Use translation function as a hook
*/
export const useTranslation = () => useI18n()[0];

export const I18nContext = createContext(i18n.translator(() => i18n.flatten(dict.en), i18n.resolveTemplate))

export const useTranslation = () => useContext(I18nContext);

const [duringI18nTransition, startI18nTransition] = useTransition();

export { duringI18nTransition };

export async function fetchLanguage(key: Language): Promise<Dictionary> {
const data = await import(`./locales/${Languages[key].i18n}.json`) as typeof dict.en;
return i18n.flatten(data)
}

/**
* Load and set a language by the given key
* set a language by the given key
*/
export async function loadAndSetLanguage(key: Language) {
if (language() === key) return;
setLanguage(key);

const data = await import(`./locales/${Languages[key].i18n}.json`);
context[1].add(key, defaultsDeep({}, data, en));
context[1].locale(key);
export function setLanguage(key: Language) {
startI18nTransition(() => _setLanguage(key));
}

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ export function browserPreferredLanguage() {
*/
export const useQuantity = () => {
const t = useTranslation();
return (id: string, count: number) =>
return (id: 'members' | 'dropFiles', count: number) =>
t(`quantities.${id}.${count > 1 ? "many" : "one"}`, {
count: count.toString(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function RenderCustomEmoji(props: CustomComponentProps) {
<Switch fallback={<span>{`:${emoji()?.name ?? props.match}:`}</span>}>
<Match when={exists()}>
<TooltipTrigger
// @ts-expect-error this is a hack; replace with plain element & panda-css
use:floating={{
tooltip: {
placement: "top",
Expand Down
4 changes: 1 addition & 3 deletions packages/client/components/markdown/sanitise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Root } from "hast";

/**
* Regex for matching execessive recursion of blockquotes and lists
*/
Expand Down Expand Up @@ -71,7 +69,7 @@ export function sanitise(content: string) {
* Replace \uF800 with break elements
*/
export function remarkInsertBreaks() {
return (tree: Root) => {
return (tree: import('hast').Root) => {
/**
* Process element and sub-tree
* @param element Element
Expand Down
2 changes: 1 addition & 1 deletion packages/client/components/modal/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function createFormModal<
<Show when={error()}>
<Error>
<Typography variant="label">
{t(`error.${error()}`, undefined, error())}
{t(`error.${error()}` as any, undefined, error())}
</Typography>
</Error>
</Show>
Expand Down
1 change: 1 addition & 0 deletions packages/client/components/modal/modals/CustomStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const CustomStatus: PropGenerator<"custom_status"> = (props) => {
data: {
text: {
field: t("app.context_menu.custom_status"),
// @ts-expect-error this is a hack; replace with plain element & panda-css
"use:autoComplete": true,
},
},
Expand Down
Loading

0 comments on commit 04ebf9e

Please sign in to comment.