-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
150 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useEffect } from "react"; | ||
|
||
const isMacOS = /Mac OS X/i.test(navigator.userAgent); | ||
|
||
// Custom hook for handling tab navigation in Safari on macOS | ||
// It's either a bug of Telegram for Mac or some issues with Safari WebView | ||
export const useMacTabNavigationFix = () => { | ||
useEffect(() => { | ||
if (!isMacOS) { | ||
return; | ||
} | ||
const handleKeyDown = (event: KeyboardEvent) => { | ||
if (event.key === "Tab") { | ||
event.preventDefault(); | ||
|
||
const inputs = Array.from(document.querySelectorAll("input, textarea")); | ||
const activeElement = document.activeElement; | ||
// @ts-expect-error | ||
const currentIndex = inputs.indexOf(activeElement); | ||
if (currentIndex === -1) { | ||
// No input is currently focused, focus the first input | ||
if (inputs.length > 0) { | ||
// @ts-expect-error | ||
inputs[0].focus(); | ||
} | ||
} else { | ||
if (event.shiftKey && currentIndex > 0) { | ||
// Shift + Tab was pressed | ||
// @ts-expect-error | ||
inputs[currentIndex - 1].focus(); | ||
} else if (!event.shiftKey && currentIndex >= 0 && currentIndex < inputs.length - 1) { | ||
// Only Tab was pressed | ||
// @ts-expect-error | ||
inputs[currentIndex + 1].focus(); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// Only keyup works here, events like keydown and keypress don't | ||
document.addEventListener("keyup", handleKeyDown); | ||
return () => { | ||
document.removeEventListener("keyup", handleKeyDown); | ||
}; | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 0 additions & 89 deletions
89
src/screens/user-settings/user-review-notification-settings.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,93 @@ | ||
import { observer } from "mobx-react-lite"; | ||
import { useUserSettingsStore } from "../../store/user-settings-store-context.tsx"; | ||
import { deckListStore } from "../../store/deck-list-store.ts"; | ||
import { UserSettingsScreen } from "../../store/user-settings-store.tsx"; | ||
import { UserReviewNotificationSettings } from "./user-review-notification-settings.tsx"; | ||
import React from "react"; | ||
import { UserSettings } from "./user-settings.tsx"; | ||
import { useMount } from "../../lib/react/use-mount.ts"; | ||
import { generateTimeRange } from "./generate-time-range.tsx"; | ||
import { useMainButton } from "../../lib/telegram/use-main-button.tsx"; | ||
import { useTelegramProgress } from "../../lib/telegram/use-telegram-progress.tsx"; | ||
import { ListHeader } from "../../ui/list-header.tsx"; | ||
import { SettingsRow } from "./settings-row.tsx"; | ||
import { RadioSwitcher } from "../../ui/radio-switcher.tsx"; | ||
import { theme } from "../../ui/theme.tsx"; | ||
import { Select } from "../../ui/select.tsx"; | ||
import { Hint } from "../../ui/hint.tsx"; | ||
import { css } from "@emotion/css"; | ||
|
||
export const timeRanges = generateTimeRange(); | ||
|
||
export const UserSettingsMain = observer(() => { | ||
const userSettingsStore = useUserSettingsStore(); | ||
|
||
useMount(() => { | ||
userSettingsStore.load(); | ||
}); | ||
|
||
useMainButton( | ||
"Save", | ||
() => userSettingsStore.submit(), | ||
() => userSettingsStore.isSaveVisible, | ||
); | ||
|
||
useTelegramProgress(() => userSettingsStore.isSending); | ||
|
||
if (deckListStore.myInfo?.state !== "fulfilled") { | ||
return null; | ||
} | ||
|
||
if (userSettingsStore.screen === UserSettingsScreen.UserReviewSettings) { | ||
return <UserReviewNotificationSettings />; | ||
if (!userSettingsStore.form) { | ||
return null; | ||
} | ||
|
||
return <UserSettings />; | ||
const { isRemindNotifyEnabled, time } = userSettingsStore.form; | ||
|
||
return ( | ||
<div> | ||
<ListHeader text={"Review notification settings"} /> | ||
|
||
<div | ||
className={css({ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: 8, | ||
})} | ||
> | ||
<SettingsRow> | ||
<span>Notifications</span> | ||
<span | ||
className={css({ | ||
transform: "translateY(3px)", | ||
position: "relative", | ||
})} | ||
> | ||
<RadioSwitcher | ||
isOn={isRemindNotifyEnabled.value} | ||
onToggle={isRemindNotifyEnabled.toggle} | ||
/> | ||
</span> | ||
</SettingsRow> | ||
{isRemindNotifyEnabled.value && ( | ||
<SettingsRow> | ||
<span>Time</span> | ||
<div className={css({ color: theme.linkColor })}> | ||
<Select | ||
value={time.value.toString()} | ||
onChange={(value) => { | ||
time.onChange(value); | ||
}} | ||
options={timeRanges.map((range) => ({ | ||
value: range, | ||
label: range, | ||
}))} | ||
/> | ||
</div> | ||
</SettingsRow> | ||
)} | ||
|
||
<Hint> | ||
⭐ Daily reminders help you keep up with your reviews, making it | ||
easier for you to remember the information | ||
</Hint> | ||
</div> | ||
</div> | ||
); | ||
}); |
Oops, something went wrong.