Skip to content

Commit

Permalink
Merge pull request #85 from ulu-telegram/master
Browse files Browse the repository at this point in the history
deploy
  • Loading branch information
ulugmer authored Nov 16, 2023
2 parents 62df5e3 + 27b801f commit 18cf70b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/components/common/CommandMenuCalendar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable react/jsx-no-bind */
/* eslint-disable no-async-without-await/no-async-without-await */
import React from 'react';
// eslint-disable-next-line react/no-deprecated
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';
import { Chrono } from 'chrono-node';
import { Command } from 'cmdk';
import {
Expand All @@ -22,7 +21,10 @@ export type OwnProps = {
onSendWhenOnline?: () => void;
isReminder?: boolean;
};
const calendarRoot = document.getElementById('calendar-root');

const calendarElement = document.getElementById('calendar-root');
const calendarRoot = createRoot(calendarElement!);

const CommandMenuCalendar = ({
isOpen,
setOpen,
Expand Down Expand Up @@ -259,7 +261,7 @@ const CommandMenuCalendar = ({
</Command.Dialog>
);

render(CommandMenuInner, calendarRoot);
calendarRoot.render(CommandMenuInner);
return <div />;
};

Expand Down
12 changes: 8 additions & 4 deletions src/components/main/CommandMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
/* eslint-disable @typescript-eslint/no-shadow */
/* eslint-disable react/jsx-no-bind */
import React from 'react';
// eslint-disable-next-line react/no-deprecated
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';
// eslint-disable-next-line react/no-deprecated
import { Command, CommandSeparator } from 'cmdk';
import type { FC } from '../../lib/teact/teact';
Expand All @@ -29,7 +28,8 @@ import { useJune } from '../../hooks/useJune';

import './CommandMenu.scss';

const cmdkRoot = document.getElementById('cmdk-root');
const cmdkElement = document.getElementById('cmdk-root');
const cmdkRoot = createRoot(cmdkElement!);
const SEARCH_CLOSE_TIMEOUT_MS = 250;

interface CommandMenuProps {
Expand Down Expand Up @@ -175,6 +175,10 @@ const HomePage: React.FC<HomePageProps> = ({
<Command.Group heading="Navigation">
<Command.Item value="$find $search" onSelect={handleSearchFocus}>
<i className="icon icon-search" /><span>Find chat or contact</span>
<span className="shortcuts">
<span className="kbd"></span>
<span className="kbd">/</span>
</span>
</Command.Item>
<Command.Item onSelect={handleOpenInbox}>
<i className="icon icon-unread" /><span>Go to inbox</span>
Expand Down Expand Up @@ -441,7 +445,7 @@ const CommandMenu: FC<CommandMenuProps> = ({ topUserIds, usersById }) => {
</Command.Dialog>
);

render(CommandMenuInner, cmdkRoot);
cmdkRoot.render(CommandMenuInner);
return <div />;
};

Expand Down
36 changes: 36 additions & 0 deletions src/hooks/useMultitouchBackSwipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useEffect, useState } from 'react';
import { ipcRenderer } from 'electron';

const useMultitouchBackSwipe = (callback: () => void, threshold = 100) => {
const [scrollPosition, setScrollPosition] = useState(0);

useEffect(() => {
const handleScrollTouchBegin = () => {
setScrollPosition(0); // Сброс позиции прокрутки при начале жеста
};

const handleScrollTouchEnd = () => {
if (scrollPosition > threshold) {
callback(); // Вызов callback, если прокрутка превысила порог
}
};

const handleWheel = (e: { deltaX: number }) => {
setScrollPosition((prev) => prev + e.deltaX); // Обновление позиции прокрутки
};

document.addEventListener('wheel', handleWheel);
ipcRenderer.on('scroll-touch-begin', handleScrollTouchBegin);
ipcRenderer.on('scroll-touch-end', handleScrollTouchEnd);

return () => {
document.removeEventListener('wheel', handleWheel);
ipcRenderer.removeListener('scroll-touch-begin', handleScrollTouchBegin);
ipcRenderer.removeListener('scroll-touch-end', handleScrollTouchEnd);
};
}, [callback, scrollPosition, threshold]);

return scrollPosition;
};

export default useMultitouchBackSwipe;
3 changes: 2 additions & 1 deletion src/util/windowEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const IS_ARC_BROWSER = navigator.userAgent.includes('Chrome')
&& !navigator.userAgent.includes('Edg')
&& !IS_FIREFOX
&& !IS_YA_BROWSER
&& !IS_SAFARI;
&& !IS_SAFARI
&& !IS_ELECTRON;

export enum MouseButton {
Main = 0,
Expand Down

0 comments on commit 18cf70b

Please sign in to comment.