From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Fri, 31 May 2024 14:19:46 +0000 (+0530) Subject: URL navigation in interface and other improvements (#1633) X-Git-Tag: v4.0.0~36 X-Git-Url: https://git.wafflesoft.org/?a=commitdiff_plain;h=4c76a7fd180c56daacae3fc3c01706aa3ea92bd2;p=cinny.git URL navigation in interface and other improvements (#1633) * load room on url change * add direct room list * render space room list * fix css syntax error * update scroll virtualizer * render subspaces room list * improve sidebar notification badge perf * add nav category components * add space recursive direct component * use nav category component in home, direct and space room list * add empty home and direct list layout * fix unread room menu ref * add more navigation items in room, direct and space tab * add more navigation * fix unread room menu to links * fix space lobby and search link * add explore navigation section * add notifications navigation menu * redirect to initial path after login * include unsupported room in rooms * move router hooks in hooks/router folder * add featured explore - WIP * load featured room with room summary * fix room card topic line clamp * add react query * load room summary using react query * add join button in room card * add content component * use content component in featured community content * fix content width * add responsive room card grid * fix async callback error status * add room card error button * fix client drawer shrink * add room topic viewer * open room card topic in viewer * fix room topic close btn * add get orphan parent util * add room card error dialog * add view featured room or space btn * refactor orphanParent to orphanParents * WIP - explore server * show space hint in room card * add room type filters * add per page item limit popout * reset scroll on public rooms load * refactor explore ui * refactor public rooms component * reset search on server change * fix typo * add empty featured section info * display user server on top * make server room card view btn clickable * add user server as default redirect for explore path * make home empty btn clickable * add thirdparty instance filter in server explore * remove since param on instance change * add server button in explore menu * rename notifications path to inbox * update react-virtual * Add notification messages inbox - WIP * add scroll top container component * add useInterval hook * add visibility change callback prop to scroll top container component * auto refresh notifications every 10 seconds * make message related component reusable * refactor matrix event renderer hoook * render notification message content * refactor matrix event renderer hook * update sequence card styles * move room navigate hook in global hooks * add open message button in notifications * add mark room as read button in notification group * show error in notification messages * add more featured spaces * render reply in notification messages * make notification message reply clickable * add outline prop for attachments * make old settings dialog viewable * add open featured communities as default config option * add invite count notification badge in sidebar and inbox menu * add element size observer hook * improve element size observer hook props * improve screen size hook * fix room avatar util function * allow Text props in Time component * fix dm room util function * add invitations * add no invites and notification cards * fix inbox tab unread badge visible without invite count * update folds and change inbox icon * memo search param construction * add message search in home * fix default message search order * fix display edited message new content * highlight search text in search messages * fix message search loading * disable log in production * add use space context * add useRoom context * fix space room list * fix inbox tab active state * add hook to get space child room recursive * add search for space * add virtual tile component * virtualize home and directs room list * update nav category component * use virtual tile component in more places * fix message highlight when click on reply twice * virtualize space room list * fix space room list lag issue * update folds * add room nav item component in space room list * use room nav item in home and direct room list * make space categories closable and save it in local storage * show unread room when category is collapsed * make home and direct room list category closable * rename room nav item show avatar prop * fix explore server category text alignment * rename closedRoomCategories to closedNavCategories * add nav category handler hook * save and restore last navigation path on space select * filter space rooms category by activity when it is closed * save and restore home and direct nav path state * save and restore inbox active path on open * save and restore explore tab active path * remove notification badge unread menu * add join room or space before navigate screen * move room component to features folder and add new room header * update folds * add room header menu * fix home room list activity sorting * do not hide selected room item on category closed in home and direct tab * replace old select room/tab call with navigate hook * improve state event hooks * show room card summary for joined rooms * prevent room from opening in wrong tab * only show message sender id on hover in modern layout * revert state event hooks changes * add key prop to room provider components * add welcome page * prevent excessive redirects * fix sidebar style with no spaces * move room settings in popup window * remove invite option from room settings * fix open room list search * add leave room prompt * standardize room and user avatar * fix avatar text size * add new reply layout * rename space hierarchy hook * add room topic hook * add room name hook * add room avatar hook and add direct room avatar util * space lobby - WIP * hide invalid space child event from space hierarchy in lobby * move lobby to features * fix element size observer hook width and height * add lobby header and hero section * add hierarchy room item error and loading state * add first and last child prop in sequence card * redirect to lobby from index path * memo and retry hierarchy room summary error * fix hierarchy room item styles * rename lobby hierarchy item card to room item card * show direct room avatar in space lobby * add hierarchy space item * add space item unknown room join button * fix space hierarchy hook refresh after new space join * change user avatar color and fallback render to user icon * change room avatar fallback to room icon * rename room/user avatar renderInitial prop to renderFallback * add room join and view button in space lobby * make power level api more reusable * fix space hierarchy not updating on child update * add menu to suggest or remove space children * show reply arrow in place of reply bend in message * fix typeerror in search because of wrong js-sdk t.ds * do not refetch hierarchy room summary on window focus * make room/user avatar un-draggable * change welcome page support button copy * drag-and-drop ordering of lobby spaces/rooms - WIP * add ASCIILexicalTable algorithms * fix wrong power level check in lobby items options * fix lobby can drop checks * fix join button error crash * fix reply spacing * fix m direct updated with other account data * add option to open room/space settings from lobby * add option in lobby to add new or existing room/spaces * fix room nav item selected styles * add space children reorder mechanism * fix space child reorder bug * fix hierarchy item sort function * Apply reorder of lobby into room list * add and improve space lobby menu items * add existing spaces menu in lobby * change restricted room allow params when dragging outside space * move featured servers config from homeserver list * removed unused features from space settings * add canonical alias as name fallback in lobby item * fix unreliable unread count update bug * fix after login redirect * fix room card topic hover style * Add dnd and folders in sidebar spaces * fix orphan space not visible in sidebar * fix sso login has mix of icon and button * fix space children not visible in home upon leaving space * recalculate notification on updating any space child * fix user color saturation/lightness * add user color to user avatar * add background colors to room avatar * show 2 length initial in sidebar space avatar * improve link color * add nav button component * open legacy create room and create direct * improve page route structure * handle hash router in path utils * mobile friendly router and navigation * make room header member drawer icon mobile friendly * setup index redirect for inbox and explore server route * add leave space prompt * improve member drawer filter menu * add space context menu * add context menu in home * add leave button in lobby items * render user tab avatar on sidebar * force overwrite netlify - test * netlify test * fix reset-password path without server redirected to login * add message link copy button in message menu * reset unread on sync prepared * fix stuck typing notifications * show typing indication in room nav item * refactor closedNavCategories atom to use userId in store key * refactor closedLobbyCategoriesAtom to include userId in store key * refactor navToActivePathAtom to use userId in storage key * remove unused file * refactor openedSidebarFolderAtom to include userId in storage key * add context menu for sidebar space tab * fix eslint not working * add option to pin/unpin child spaces * add context menu for directs tab * add context menu for direct and home tab * show lock icon for non-public space in header * increase matrix max listener count * wrap lobby add space room in callback hook --- diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..36101fb --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,64 @@ +module.exports = { + env: { + browser: true, + es2021: true, + }, + extends: [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:react-hooks/recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + 'airbnb', + 'prettier', + ], + parser: "@typescript-eslint/parser", + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + ecmaVersion: 'latest', + sourceType: 'module', + }, + "globals": { + JSX: "readonly" + }, + plugins: [ + 'react', + '@typescript-eslint' + ], + rules: { + 'linebreak-style': 0, + 'no-underscore-dangle': 0, + "no-shadow": "off", + + "import/prefer-default-export": "off", + "import/extensions": "off", + "import/no-unresolved": "off", + "import/no-extraneous-dependencies": [ + "error", + { + devDependencies: true, + }, + ], + + 'react/no-unstable-nested-components': [ + 'error', + { allowAsProps: true }, + ], + "react/jsx-filename-extension": [ + "error", + { + extensions: [".tsx", ".jsx"], + }, + ], + + "react/require-default-props": "off", + "react/jsx-props-no-spreading": "off", + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "error", + + "@typescript-eslint/no-unused-vars": "error", + "@typescript-eslint/no-shadow": "error" + }, +}; diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 36101fb..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,64 +0,0 @@ -module.exports = { - env: { - browser: true, - es2021: true, - }, - extends: [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:react-hooks/recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended", - 'airbnb', - 'prettier', - ], - parser: "@typescript-eslint/parser", - parserOptions: { - ecmaFeatures: { - jsx: true, - }, - ecmaVersion: 'latest', - sourceType: 'module', - }, - "globals": { - JSX: "readonly" - }, - plugins: [ - 'react', - '@typescript-eslint' - ], - rules: { - 'linebreak-style': 0, - 'no-underscore-dangle': 0, - "no-shadow": "off", - - "import/prefer-default-export": "off", - "import/extensions": "off", - "import/no-unresolved": "off", - "import/no-extraneous-dependencies": [ - "error", - { - devDependencies: true, - }, - ], - - 'react/no-unstable-nested-components': [ - 'error', - { allowAsProps: true }, - ], - "react/jsx-filename-extension": [ - "error", - { - extensions: [".tsx", ".jsx"], - }, - ], - - "react/require-default-props": "off", - "react/jsx-props-no-spreading": "off", - "react-hooks/rules-of-hooks": "error", - "react-hooks/exhaustive-deps": "error", - - "@typescript-eslint/no-unused-vars": "error", - "@typescript-eslint/no-shadow": "error" - }, -}; diff --git a/config.json b/config.json index 484c7cd..762c3a3 100644 --- a/config.json +++ b/config.json @@ -10,6 +10,26 @@ ], "allowCustomHomeservers": true, + "featuredCommunities": { + "openAsDefault": false, + "spaces": [ + "#cinny-space:matrix.org", + "#community:matrix.org", + "#space:envs.net", + "#science-space:matrix.org", + "#libregaming-games:tchncs.de", + "#mathematics-on:matrix.org" + ], + "rooms": [ + "#cinny:matrix.org", + "#foundation-office:matrix.org", + "#thisweekinmatrix:matrix.org", + "#matrix-dev:matrix.org", + "#matrix:matrix.org" + ], + "servers": ["envs.net", "matrix.org", "monero.social", "mozilla.org"] + }, + "hashRouter": { "enabled": false, "basename": "/" diff --git a/netlify.toml b/netlify.toml index e7d948e..d79aa91 100644 --- a/netlify.toml +++ b/netlify.toml @@ -9,9 +9,10 @@ status = 200 [[redirects]] - from = "/olm.wasm" + from = "*/olm.wasm" to = "/olm.wasm" status = 200 + force = true [[redirects]] from = "/pdf.worker.min.js" @@ -31,4 +32,5 @@ [[redirects]] from = "/*" to = "/index.html" - status = 200 \ No newline at end of file + status = 200 + force = true \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2eec291..17e4dd5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,15 @@ "version": "3.2.0", "license": "AGPL-3.0-only", "dependencies": { + "@atlaskit/pragmatic-drag-and-drop": "1.1.6", + "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "1.3.0", + "@atlaskit/pragmatic-drag-and-drop-hitbox": "1.0.3", "@fontsource/inter": "4.5.14", "@khanacademy/simple-markdown": "0.8.6", "@matrix-org/olm": "3.2.14", - "@tanstack/react-virtual": "3.0.0-beta.54", + "@tanstack/react-query": "5.24.1", + "@tanstack/react-query-devtools": "5.24.1", + "@tanstack/react-virtual": "3.2.0", "@tippyjs/react": "4.2.6", "@vanilla-extract/css": "1.9.3", "@vanilla-extract/recipes": "0.3.0", @@ -29,7 +34,7 @@ "file-saver": "2.0.5", "flux": "4.0.3", "focus-trap-react": "10.0.2", - "folds": "1.5.1", + "folds": "2.0.0", "formik": "2.2.9", "html-dom-parser": "4.0.0", "html-react-parser": "4.2.0", @@ -111,6 +116,34 @@ "node": ">=6.0.0" } }, + "node_modules/@atlaskit/pragmatic-drag-and-drop": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@atlaskit/pragmatic-drag-and-drop/-/pragmatic-drag-and-drop-1.1.6.tgz", + "integrity": "sha512-+jGspaRMyHWB6g9w+N1KImS5I+xt0ML89pwUyCueEhf2KGsl6zyH9ZxjTVKfrbY89FyZvuuXT9oFRHTUKGBi/w==", + "dependencies": { + "@babel/runtime": "^7.0.0", + "bind-event-listener": "^3.0.0", + "raf-schd": "^4.0.3" + } + }, + "node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@atlaskit/pragmatic-drag-and-drop-auto-scroll/-/pragmatic-drag-and-drop-auto-scroll-1.3.0.tgz", + "integrity": "sha512-8wjKAI5qSrLojt8ZJ2WhoS5P75oBu5g0yMpAnTDgfqFyQnkt5Uc1txCRWpG26SS1mv19nm8ak9XHF2DOugVfpw==", + "dependencies": { + "@atlaskit/pragmatic-drag-and-drop": "^1.1.0", + "@babel/runtime": "^7.0.0" + } + }, + "node_modules/@atlaskit/pragmatic-drag-and-drop-hitbox": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@atlaskit/pragmatic-drag-and-drop-hitbox/-/pragmatic-drag-and-drop-hitbox-1.0.3.tgz", + "integrity": "sha512-/Sbu/HqN2VGLYBhnsG7SbRNg98XKkbF6L7XDdBi+izRybfaK1FeMfodPpm/xnBHPJzwYMdkE0qtLyv6afhgMUA==", + "dependencies": { + "@atlaskit/pragmatic-drag-and-drop": "^1.1.0", + "@babel/runtime": "^7.0.0" + } + }, "node_modules/@babel/code-frame": { "version": "7.23.4", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.4.tgz", @@ -3093,25 +3126,75 @@ "@swc/counter": "^0.1.3" } }, + "node_modules/@tanstack/query-core": { + "version": "5.24.1", + "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.24.1.tgz", + "integrity": "sha512-DZ6Nx9p7BhjkG50ayJ+MKPgff+lMeol7QYXkvuU5jr2ryW/4ok5eanaS9W5eooA4xN0A/GPHdLGOZGzArgf5Cg==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tanstack/query-devtools": { + "version": "5.24.0", + "resolved": "https://registry.npmjs.org/@tanstack/query-devtools/-/query-devtools-5.24.0.tgz", + "integrity": "sha512-pThim455t69zrZaQKa7IRkEIK8UBTS+gHVAdNfhO72Xh4rWpMc63ovRje5/n6iw63+d6QiJzVadsJVdPoodSeQ==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tanstack/react-query": { + "version": "5.24.1", + "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.24.1.tgz", + "integrity": "sha512-4+09JEdO4d6+Gc8Y/g2M/MuxDK5IY0QV8+2wL2304wPKJgJ54cBbULd3nciJ5uvh/as8rrxx6s0mtIwpRuGd1g==", + "dependencies": { + "@tanstack/query-core": "5.24.1" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": "^18.0.0" + } + }, + "node_modules/@tanstack/react-query-devtools": { + "version": "5.24.1", + "resolved": "https://registry.npmjs.org/@tanstack/react-query-devtools/-/react-query-devtools-5.24.1.tgz", + "integrity": "sha512-qa4SEugN+EF8JJXcpsM9Lu05HfUv5cvHvLuB0uw/81eJZyNHFdtHFBi5RLCgpBrOyVMDfH8UQ3VBMqXzFKV68A==", + "dependencies": { + "@tanstack/query-devtools": "5.24.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "@tanstack/react-query": "^5.24.1", + "react": "^18.0.0" + } + }, "node_modules/@tanstack/react-virtual": { - "version": "3.0.0-beta.54", - "resolved": "https://registry.npmjs.org/@tanstack/react-virtual/-/react-virtual-3.0.0-beta.54.tgz", - "integrity": "sha512-D1mDMf4UPbrtHRZZriCly5bXTBMhylslm4dhcHqTtDJ6brQcgGmk8YD9JdWBGWfGSWPKoh2x1H3e7eh+hgPXtQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@tanstack/react-virtual/-/react-virtual-3.2.0.tgz", + "integrity": "sha512-OEdMByf2hEfDa6XDbGlZN8qO6bTjlNKqjM3im9JG+u3mCL8jALy0T/67oDI001raUUPh1Bdmfn4ZvPOV5knpcg==", "dependencies": { - "@tanstack/virtual-core": "3.0.0-beta.54" + "@tanstack/virtual-core": "3.2.0" }, "funding": { "type": "github", "url": "https://github.com/sponsors/tannerlinsley" }, "peerDependencies": { - "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + "react": "^16.8.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0" } }, "node_modules/@tanstack/virtual-core": { - "version": "3.0.0-beta.54", - "resolved": "https://registry.npmjs.org/@tanstack/virtual-core/-/virtual-core-3.0.0-beta.54.tgz", - "integrity": "sha512-jtkwqdP2rY2iCCDVAFuaNBH3fiEi29aTn2RhtIoky8DTTiCdc48plpHHreLwmv1PICJ4AJUUESaq3xa8fZH8+g==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@tanstack/virtual-core/-/virtual-core-3.2.0.tgz", + "integrity": "sha512-P5XgYoAw/vfW65byBbJQCw+cagdXDT/qH6wmABiLt4v4YBT2q2vqCOhihe+D1Nt325F/S/0Tkv6C5z0Lv+VBQQ==", "funding": { "type": "github", "url": "https://github.com/sponsors/tannerlinsley" @@ -4065,6 +4148,11 @@ "node": ">=8" } }, + "node_modules/bind-event-listener": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bind-event-listener/-/bind-event-listener-3.0.0.tgz", + "integrity": "sha512-PJvH288AWQhKs2v9zyfYdPzlPqf5bXbGMmhmUIY9x4dAUGIWgomO771oBQNwJnMQSnUIXhKu6sgzpBRXTlvb8Q==" + }, "node_modules/blurhash": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/blurhash/-/blurhash-2.0.4.tgz", @@ -5665,9 +5753,9 @@ } }, "node_modules/folds": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/folds/-/folds-1.5.1.tgz", - "integrity": "sha512-2QxyA+FRKjPKXDTMDoD7NmOUiReWrKYO0Msg44QqlzTkTrRVEzJgyPIfC/Ia4/u0ByQpk6dbq8UQxomKmneJ/g==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/folds/-/folds-2.0.0.tgz", + "integrity": "sha512-lKv31vij4GEpEzGKWk5c3ar78fMZ9Di5n1XFR14Z2wnnpqhiiM5JTIzr127Gk5dOfy4mJkjnv/ZfMZvM2k+OQg==", "peerDependencies": { "@vanilla-extract/css": "^1.9.2", "@vanilla-extract/recipes": "^0.3.0", @@ -7580,6 +7668,11 @@ } ] }, + "node_modules/raf-schd": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/raf-schd/-/raf-schd-4.0.3.tgz", + "integrity": "sha512-tQkJl2GRWh83ui2DiPTJz9wEiMN20syf+5oKfB03yYP7ioZcJwsIK8FjrtLwH1m7C7e+Tt2yYBlrOpdT+dyeIQ==" + }, "node_modules/react": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", diff --git a/package.json b/package.json index 44c28d3..e626e83 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,15 @@ "author": "Ajay Bura", "license": "AGPL-3.0-only", "dependencies": { + "@atlaskit/pragmatic-drag-and-drop": "1.1.6", + "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "1.3.0", + "@atlaskit/pragmatic-drag-and-drop-hitbox": "1.0.3", "@fontsource/inter": "4.5.14", "@khanacademy/simple-markdown": "0.8.6", "@matrix-org/olm": "3.2.14", - "@tanstack/react-virtual": "3.0.0-beta.54", + "@tanstack/react-query": "5.24.1", + "@tanstack/react-query-devtools": "5.24.1", + "@tanstack/react-virtual": "3.2.0", "@tippyjs/react": "4.2.6", "@vanilla-extract/css": "1.9.3", "@vanilla-extract/recipes": "0.3.0", @@ -40,7 +45,7 @@ "file-saver": "2.0.5", "flux": "4.0.3", "focus-trap-react": "10.0.2", - "folds": "1.5.1", + "folds": "2.0.0", "formik": "2.2.9", "html-dom-parser": "4.0.0", "html-react-parser": "4.2.0", diff --git a/src/app/components/CapabilitiesAndMediaConfigLoader.tsx b/src/app/components/CapabilitiesAndMediaConfigLoader.tsx new file mode 100644 index 0000000..338e528 --- /dev/null +++ b/src/app/components/CapabilitiesAndMediaConfigLoader.tsx @@ -0,0 +1,36 @@ +import { ReactNode, useCallback, useEffect } from 'react'; +import { Capabilities } from 'matrix-js-sdk'; +import { AsyncStatus, useAsyncCallback } from '../hooks/useAsyncCallback'; +import { useMatrixClient } from '../hooks/useMatrixClient'; +import { MediaConfig } from '../hooks/useMediaConfig'; +import { promiseFulfilledResult } from '../utils/common'; + +type CapabilitiesAndMediaConfigLoaderProps = { + children: (capabilities?: Capabilities, mediaConfig?: MediaConfig) => ReactNode; +}; +export function CapabilitiesAndMediaConfigLoader({ + children, +}: CapabilitiesAndMediaConfigLoaderProps) { + const mx = useMatrixClient(); + + const [state, load] = useAsyncCallback< + [Capabilities | undefined, MediaConfig | undefined], + unknown, + [] + >( + useCallback(async () => { + const result = await Promise.allSettled([mx.getCapabilities(true), mx.getMediaConfig()]); + const capabilities = promiseFulfilledResult(result[0]); + const mediaConfig = promiseFulfilledResult(result[1]); + return [capabilities, mediaConfig]; + }, [mx]) + ); + + useEffect(() => { + load(); + }, [load]); + + const [capabilities, mediaConfig] = + state.status === AsyncStatus.Success ? state.data : [undefined, undefined]; + return children(capabilities, mediaConfig); +} diff --git a/src/app/components/CapabilitiesLoader.tsx b/src/app/components/CapabilitiesLoader.tsx new file mode 100644 index 0000000..dad59ec --- /dev/null +++ b/src/app/components/CapabilitiesLoader.tsx @@ -0,0 +1,19 @@ +import { ReactNode, useCallback, useEffect } from 'react'; +import { Capabilities } from 'matrix-js-sdk'; +import { AsyncStatus, useAsyncCallback } from '../hooks/useAsyncCallback'; +import { useMatrixClient } from '../hooks/useMatrixClient'; + +type CapabilitiesLoaderProps = { + children: (capabilities: Capabilities | undefined) => ReactNode; +}; +export function CapabilitiesLoader({ children }: CapabilitiesLoaderProps) { + const mx = useMatrixClient(); + + const [state, load] = useAsyncCallback(useCallback(() => mx.getCapabilities(true), [mx])); + + useEffect(() => { + load(); + }, [load]); + + return children(state.status === AsyncStatus.Success ? state.data : undefined); +} diff --git a/src/app/components/MediaConfigLoader.tsx b/src/app/components/MediaConfigLoader.tsx new file mode 100644 index 0000000..9fd9933 --- /dev/null +++ b/src/app/components/MediaConfigLoader.tsx @@ -0,0 +1,19 @@ +import { ReactNode, useCallback, useEffect } from 'react'; +import { AsyncStatus, useAsyncCallback } from '../hooks/useAsyncCallback'; +import { useMatrixClient } from '../hooks/useMatrixClient'; +import { MediaConfig } from '../hooks/useMediaConfig'; + +type MediaConfigLoaderProps = { + children: (mediaConfig: MediaConfig | undefined) => ReactNode; +}; +export function MediaConfigLoader({ children }: MediaConfigLoaderProps) { + const mx = useMatrixClient(); + + const [state, load] = useAsyncCallback(useCallback(() => mx.getMediaConfig(), [mx])); + + useEffect(() => { + load(); + }, [load]); + + return children(state.status === AsyncStatus.Success ? state.data : undefined); +} diff --git a/src/app/components/Pdf-viewer/PdfViewer.tsx b/src/app/components/Pdf-viewer/PdfViewer.tsx index c440cce..a78c13f 100644 --- a/src/app/components/Pdf-viewer/PdfViewer.tsx +++ b/src/app/components/Pdf-viewer/PdfViewer.tsx @@ -1,6 +1,6 @@ /* eslint-disable no-param-reassign */ /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ -import React, { FormEventHandler, useEffect, useRef, useState } from 'react'; +import React, { FormEventHandler, MouseEventHandler, useEffect, useRef, useState } from 'react'; import classNames from 'classnames'; import { Box, @@ -13,6 +13,7 @@ import { Input, Menu, PopOut, + RectCords, Scroll, Spinner, Text, @@ -48,7 +49,7 @@ export const PdfViewer = as<'div', PdfViewerProps>( const isError = pdfJSState.status === AsyncStatus.Error || docState.status === AsyncStatus.Error; const [pageNo, setPageNo] = useState(1); - const [openJump, setOpenJump] = useState(false); + const [jumpAnchor, setJumpAnchor] = useState(); useEffect(() => { loadPdfJS(); @@ -86,7 +87,7 @@ export const PdfViewer = as<'div', PdfViewerProps>( if (!jumpInput) return; const jumpTo = parseInt(jumpInput.value, 10); setPageNo(Math.max(1, Math.min(docState.data.numPages, jumpTo))); - setOpenJump(false); + setJumpAnchor(undefined); }; const handlePrevPage = () => { @@ -98,6 +99,10 @@ export const PdfViewer = as<'div', PdfViewerProps>( setPageNo((n) => Math.min(n + 1, docState.data.numPages)); }; + const handleOpenJump: MouseEventHandler = (evt) => { + setJumpAnchor(evt.currentTarget.getBoundingClientRect()); + }; + return (
@@ -187,14 +192,14 @@ export const PdfViewer = as<'div', PdfViewerProps>( setOpenJump(false), + onDeactivate: () => setJumpAnchor(undefined), clickOutsideDeactivates: true, }} > @@ -227,17 +232,14 @@ export const PdfViewer = as<'div', PdfViewerProps>( } > - {(anchorRef) => ( - setOpenJump(!openJump)} - ref={anchorRef} - variant="SurfaceVariant" - radii="300" - aria-pressed={openJump} - > - {`${pageNo}/${docState.data.numPages}`} - - )} + + {`${pageNo}/${docState.data.numPages}`} + () => T; + mediaAutoLoad?: boolean; + urlPreview?: boolean; + highlightRegex?: RegExp; + htmlReactParserOptions: HTMLReactParserOptions; + outlineAttachment?: boolean; +}; +export function RenderMessageContent({ + displayName, + msgType, + ts, + edited, + getContent, + mediaAutoLoad, + urlPreview, + highlightRegex, + htmlReactParserOptions, + outlineAttachment, +}: RenderMessageContentProps) { + const renderFile = () => ( + ( + ( + } + /> + )} + renderAsTextFile={() => ( + } + /> + )} + > + + + )} + outlined={outlineAttachment} + /> + ); + + if (msgType === MsgType.Text) { + return ( + ( + + )} + renderUrlsPreview={ + urlPreview + ? (urls) => ( + + {urls.map((url) => ( + + ))} + + ) + : undefined + } + /> + ); + } + + if (msgType === MsgType.Emote) { + return ( + ( + + )} + renderUrlsPreview={ + urlPreview + ? (urls) => ( + + {urls.map((url) => ( + + ))} + + ) + : undefined + } + /> + ); + } + + if (msgType === MsgType.Notice) { + return ( + ( + + )} + renderUrlsPreview={ + urlPreview + ? (urls) => ( + + {urls.map((url) => ( + + ))} + + ) + : undefined + } + /> + ); + } + + if (msgType === MsgType.Image) { + return ( + ( + } + renderViewer={(p) => } + /> + )} + outlined={outlineAttachment} + /> + ); + } + + if (msgType === MsgType.Video) { + return ( + ( + ( + ( + {body} + )} + /> + ) + : undefined + } + renderVideo={(p) =>