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

Fixed 'update search results' behavior when receiving a new message #201

Merged
merged 18 commits into from
Aug 25, 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
6 changes: 6 additions & 0 deletions .changeset/tiny-trees-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rchat/client': minor
'@rchat/react': minor
---

Fixed 'update search results' behavior when receiving a new message
9 changes: 0 additions & 9 deletions .eslintignore

This file was deleted.

7 changes: 0 additions & 7 deletions .eslintrc

This file was deleted.

35 changes: 0 additions & 35 deletions .github/workflows/changeset.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Continuous Integration
on:
pull_request:
branches: [main]
types: [labeled, opened, synchronize, reopened]
jobs:
# build:
# name: Build, test & lint
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# with:
# fetch-depth: 0

# - name: Use Node 20
# uses: actions/setup-node@v4
# with:
# node-version: 20

# - name: Install pnpm 9.8.0
# uses: pnpm/[email protected]
# with:
# version: 9.8.0

# - name: Install pnpm dependencies (with cache)
# uses: covbot/pnpm-install-with-cache@v1

# - name: Build, test & lint
# run: pnpm run ci --filter=...[${{ github.event.pull_request.base.sha }}...${{ github.sha }}]
changeset:
name: Check for changeset existence
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'chore') }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Node 20
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm 9.8.0
uses: pnpm/[email protected]
with:
version: 9.8.0

- name: Install pnpm dependencies (with cache)
uses: covbot/pnpm-install-with-cache@v1

- name: Danger
run: pnpm danger ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Node.js 16.x
uses: actions/setup-node@v2
- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20

- name: Install pnpm 8.6.12
uses: pnpm/action-setup@v2.2.4
- name: Install pnpm 9.8.0
uses: pnpm/action-setup@v4.0.0
with:
version: 8.6.12
version: 9.8.0

- name: Install pnpm dependencies (with cache)
uses: covbot/pnpm-install-with-cache@v1
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ yarn-error.log*

scripts/*.mjs
coverage
**/.turbo
**/.turbo
**/.storybook
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
"name": "rchat",
"version": "0.0.0",
"private": true,
"packageManager": "[email protected]",
"scripts": {
"build": "turbo run build",
"bump": "changeset version && pnpm i --lockfile-only",
"ci": "turbo run lint test build",
"dev": "turbo run dev --parallel",
"ci": "turbo run lint test build --env-mode=loose",
"dev": "turbo watch build",
"format": "syncpack format && prettier --write **/*.{ts,tsx,js,jsx,json,yml,md}",
"release": "pnpm build && changeset tag && pnpm publish -r"
},
"devDependencies": {
"@changesets/cli": "^2.26.0",
"@types/jest": "^29.2.0",
"clean-publish": "^4.0.1",
"danger": "^11.2.4",
"prettier": "^2.8.4",
"syncpack": "^8.2.4",
"turbo": "^1.4.3",
"typescript": "^5.0.4"
"@changesets/cli": "^2.27.7",
"@types/jest": "^29.5.12",
"clean-publish": "^5.0.0",
"danger": "^12.3.3",
"prettier": "^3.3.3",
"syncpack": "^12.4.0",
"turbo": "^2.0.14",
"typescript": "^5.5.4"
},
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
}
},
"packageManager": "[email protected]"
}
17 changes: 17 additions & 0 deletions packages/client/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import config from '@sirse-dev/eslint-config';

export default [
{
ignores: [
'**/node_modules',
'**/dist',
'**/*.config.js',
'**/*.test.js',
'**/*.test.ts',
'**/stories',
'**/test',
'**/prepared-package',
],
},
...config,
];
6 changes: 3 additions & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"directory": "prepared-package"
},
"scripts": {
"build": "aqu build",
"dev": "aqu watch --no-cleanup",
"build": "aqu build && rimraf ./prepared-package && clean-publish",
"lint": "eslint **/*.{ts,tsx}",
"postpublish": "rimraf ./prepared-package",
"prepublishOnly": "rimraf ./prepared-package && clean-publish"
"prepublishOnly": "pnpm build"
},
"dependencies": {
"@rchat/shared": "workspace:*"
Expand Down
15 changes: 11 additions & 4 deletions packages/client/src/ChatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ type Self<T> = T;

export type ChatClientEventMap<TMessage> = Self<
ChatSocketListenMap<TMessage> & {
receiveSearchResults: (roomIdentifier: string, result: MessageSearchResult<TMessage>) => void;
receiveSearchResults: (
roomIdentifier: string,
result: MessageSearchResult<TMessage>,
focusIndex: number,
) => void;
nextSearchResult: (roomIdentifier: string) => void;
previousSearchResult: (roomIdentifier: string) => void;
}
Expand All @@ -18,7 +22,10 @@ export class ChatClient<TMessage> extends CustomEventTarget<ChatClientEventMap<T

public constructor(url: string, api: ChatAPI<TMessage>);
public constructor(socket: ChatClientSocket<TMessage>, api: ChatAPI<TMessage>);
public constructor(urlOrSocket: string | ChatClientSocket<TMessage>, private readonly api: ChatAPI<TMessage>) {
public constructor(
urlOrSocket: string | ChatClientSocket<TMessage>,
private readonly api: ChatAPI<TMessage>,
) {
super();
if (typeof urlOrSocket === 'string') {
this.socket = io(urlOrSocket);
Expand All @@ -36,10 +43,10 @@ export class ChatClient<TMessage> extends CustomEventTarget<ChatClientEventMap<T

public fetchMessages: MessageFetcher<TMessage>;

public searchMessages = async (roomIdentifier: string, criteria: unknown) => {
public searchMessages = async (roomIdentifier: string, criteria: unknown, focusIndex: number) => {
const result = await this.api.searchMessages(roomIdentifier, criteria);

this.dispatchEvent('receiveSearchResults', roomIdentifier, result);
this.dispatchEvent('receiveSearchResults', roomIdentifier, result, focusIndex);

return {
result,
Expand Down
1 change: 0 additions & 1 deletion packages/material/.eslintignore

This file was deleted.

14 changes: 0 additions & 14 deletions packages/material/.storybook/main.js

This file was deleted.

5 changes: 0 additions & 5 deletions packages/material/.storybook/preview-head.html

This file was deleted.

9 changes: 0 additions & 9 deletions packages/material/.storybook/preview.js

This file was deleted.

22 changes: 22 additions & 0 deletions packages/material/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import config from '@sirse-dev/eslint-config';

export default [
{
ignores: [
'**/node_modules',
'**/dist',
'**/*.config.js',
'**/*.test.js',
'**/*.test.ts',
'**/stories',
'**/test',
'**/prepared-package',
],
},
...config,
{
rules: {
'@typescript-eslint/no-empty-object-type': 'off',
},
},
];
9 changes: 3 additions & 6 deletions packages/material/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
"directory": "prepared-package"
},
"scripts": {
"build": "tsc",
"build": "tsc && rimraf ./prepared-package && clean-publish",
"build-storybook": "build-storybook",
"dev": "tsc --watch",
"lint": "eslint **/*.{ts,tsx}",
"lint:fix": "eslint . --fix",
"postpublish": "rimraf ./prepared-package",
"prepublishOnly": "rimraf ./prepared-package && clean-publish",
"prepublishOnly": "pnpm build",
"release": "np",
"storybook": "cross-env NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 6006",
"test": "aqu test --passWithNoTests",
"test:watch": "aqu test --passWithNoTests --watch"
"storybook": "cross-env NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 6006"
},
"dependencies": {
"@mui/icons-material": "^5.10.6",
Expand Down
8 changes: 4 additions & 4 deletions packages/material/src/AccountAvatar/AccountAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Avatar, { AvatarProps } from '@mui/material/Avatar';
import PersonRounded from '@mui/icons-material/PersonRounded';
import Avatar, { AvatarProps } from '@mui/material/Avatar';
import { getContrastRatio } from '@mui/system/colorManipulator';
import { ElementType } from 'react';
import { styled } from '../styles/styled';
Expand All @@ -19,14 +19,14 @@ const AccountAvatarRoot = styled<InternalAccountAvatarProps, typeof Avatar>(Avat
return { width: 28, height: 28, color, backgroundColor, fontSize: theme.typography.body2.fontSize };
});

const getInitials = (username: string): string | null => {
const getInitials = (username: string): string | undefined => {
const words = username
.split(/\s+/g)
.map((value) => value.replace(/[^\p{L}]/gu, ''))
.map((value) => value.replaceAll(/[^\p{L}]/gu, ''))
.filter(Boolean);

if (words.length === 0) {
return null;
return undefined;
}

return words[0][0] + (words[1]?.[0] || '');
Expand Down
4 changes: 2 additions & 2 deletions packages/material/src/MessageBox/MessageBox.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CSSObject } from '@mui/material';
import { ElementType, forwardRef, ReactElement, Ref } from 'react';
import { MessageOrientation } from './MessageOrientation';
import { MessageTime } from './MessageTime';
import { AccountAvatar } from '../AccountAvatar';
import { createMuiComponent, MuiComponentProps } from '../helpers/createMuiComponent';
import { MuiAccountInfo } from '../helpers/MuiAccountInfo';
import { styled } from '../styles/styled';
import { MessageOrientation } from './MessageOrientation';
import { MessageTime } from './MessageTime';

export type MessagePosition = 'start' | 'middle' | 'end' | 'single';

Expand Down
Loading
Loading