mirror of
https://github.com/yang991178/fluent-reader.git
synced 2025-02-27 08:57:44 +01:00
event handler cleanups
This commit is contained in:
parent
5927bf3441
commit
f0234afd9e
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fluent-reader",
|
"name": "fluent-reader",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -5,6 +5,7 @@ import { RSSItem } from "../scripts/models/item"
|
|||||||
import { Stack, CommandBarButton, IContextualMenuProps, FocusZone, ContextualMenuItemType, Spinner, Icon, Link } from "@fluentui/react"
|
import { Stack, CommandBarButton, IContextualMenuProps, FocusZone, ContextualMenuItemType, Spinner, Icon, Link } from "@fluentui/react"
|
||||||
import { RSSSource, SourceOpenTarget } from "../scripts/models/source"
|
import { RSSSource, SourceOpenTarget } from "../scripts/models/source"
|
||||||
import { shareSubmenu } from "./context-menu"
|
import { shareSubmenu } from "./context-menu"
|
||||||
|
import { platformCtrl } from "../scripts/utils"
|
||||||
|
|
||||||
const FONT_SIZE_OPTIONS = [12, 13, 14, 15, 16, 17, 18, 19, 20]
|
const FONT_SIZE_OPTIONS = [12, 13, 14, 15, 16, 17, 18, 19, 20]
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ type ArticleProps = {
|
|||||||
item: RSSItem
|
item: RSSItem
|
||||||
source: RSSSource
|
source: RSSSource
|
||||||
locale: string
|
locale: string
|
||||||
shortcuts: (item: RSSItem, key: string) => void
|
shortcuts: (item: RSSItem, e: KeyboardEvent) => void
|
||||||
dismiss: () => void
|
dismiss: () => void
|
||||||
offsetItem: (offset: number) => void
|
offsetItem: (offset: number) => void
|
||||||
toggleHasRead: (item: RSSItem) => void
|
toggleHasRead: (item: RSSItem) => void
|
||||||
@ -72,7 +73,7 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
|||||||
key: "openInBrowser",
|
key: "openInBrowser",
|
||||||
text: intl.get("openExternal"),
|
text: intl.get("openExternal"),
|
||||||
iconProps: { iconName: "NavigateExternalInline" },
|
iconProps: { iconName: "NavigateExternalInline" },
|
||||||
onClick: e => { window.utils.openExternal(this.props.item.link, window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey) }
|
onClick: e => { window.utils.openExternal(this.props.item.link, platformCtrl(e)) }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "copyURL",
|
key: "copyURL",
|
||||||
@ -117,7 +118,6 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
|||||||
this.toggleWebpage()
|
this.toggleWebpage()
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
this.props.shortcuts(this.props.item, input.key)
|
|
||||||
const keyboardEvent = new KeyboardEvent("keydown", {
|
const keyboardEvent = new KeyboardEvent("keydown", {
|
||||||
code: input.code,
|
code: input.code,
|
||||||
key: input.key,
|
key: input.key,
|
||||||
@ -128,6 +128,7 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
|||||||
repeat: input.isAutoRepeat,
|
repeat: input.isAutoRepeat,
|
||||||
bubbles: true
|
bubbles: true
|
||||||
})
|
})
|
||||||
|
this.props.shortcuts(this.props.item, keyboardEvent)
|
||||||
document.dispatchEvent(keyboardEvent)
|
document.dispatchEvent(keyboardEvent)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { RSSSource, SourceOpenTarget } from "../../scripts/models/source"
|
import { RSSSource, SourceOpenTarget } from "../../scripts/models/source"
|
||||||
import { RSSItem } from "../../scripts/models/item"
|
import { RSSItem } from "../../scripts/models/item"
|
||||||
|
import { platformCtrl } from "../../scripts/utils"
|
||||||
|
|
||||||
export namespace Card {
|
export namespace Card {
|
||||||
export type Props = {
|
export type Props = {
|
||||||
@ -8,7 +9,7 @@ export namespace Card {
|
|||||||
item: RSSItem
|
item: RSSItem
|
||||||
source: RSSSource
|
source: RSSSource
|
||||||
keyword: string
|
keyword: string
|
||||||
shortcuts: (item: RSSItem, key: string) => void
|
shortcuts: (item: RSSItem, e: KeyboardEvent) => void
|
||||||
markRead: (item: RSSItem) => void
|
markRead: (item: RSSItem) => void
|
||||||
contextMenu: (feedId: string, item: RSSItem, e) => void
|
contextMenu: (feedId: string, item: RSSItem, e) => void
|
||||||
showItem: (fid: string, item: RSSItem) => void
|
showItem: (fid: string, item: RSSItem) => void
|
||||||
@ -16,7 +17,7 @@ export namespace Card {
|
|||||||
|
|
||||||
const openInBrowser = (props: Props, e: React.MouseEvent) => {
|
const openInBrowser = (props: Props, e: React.MouseEvent) => {
|
||||||
props.markRead(props.item)
|
props.markRead(props.item)
|
||||||
window.utils.openExternal(props.item.link, window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey)
|
window.utils.openExternal(props.item.link, platformCtrl(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const bindEventsToProps = (props: Props) => ({
|
export const bindEventsToProps = (props: Props) => ({
|
||||||
@ -55,6 +56,6 @@ export namespace Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onKeyDown = (props: Props, e: React.KeyboardEvent) => {
|
const onKeyDown = (props: Props, e: React.KeyboardEvent) => {
|
||||||
props.shortcuts(props.item, e.key)
|
props.shortcuts(props.item, e.nativeEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import intl from "react-intl-universal"
|
import intl from "react-intl-universal"
|
||||||
import QRCode from "qrcode.react"
|
import QRCode from "qrcode.react"
|
||||||
import { cutText, webSearch, getSearchEngineName } from "../scripts/utils"
|
import { cutText, webSearch, getSearchEngineName, platformCtrl } from "../scripts/utils"
|
||||||
import { ContextualMenu, IContextualMenuItem, ContextualMenuItemType, DirectionalHint } from "office-ui-fabric-react/lib/ContextualMenu"
|
import { ContextualMenu, IContextualMenuItem, ContextualMenuItemType, DirectionalHint } from "office-ui-fabric-react/lib/ContextualMenu"
|
||||||
import { ContextMenuType } from "../scripts/models/app"
|
import { ContextMenuType } from "../scripts/models/app"
|
||||||
import { RSSItem } from "../scripts/models/item"
|
import { RSSItem } from "../scripts/models/item"
|
||||||
@ -77,7 +77,7 @@ export class ContextMenu extends React.Component<ContextMenuProps> {
|
|||||||
iconProps: { iconName: "NavigateExternalInline" },
|
iconProps: { iconName: "NavigateExternalInline" },
|
||||||
onClick: (e) => {
|
onClick: (e) => {
|
||||||
this.props.markRead(this.props.item)
|
this.props.markRead(this.props.item)
|
||||||
window.utils.openExternal(this.props.item.link, window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey)
|
window.utils.openExternal(this.props.item.link, platformCtrl(e))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -158,7 +158,7 @@ export class ContextMenu extends React.Component<ContextMenuProps> {
|
|||||||
text: intl.get("openExternal"),
|
text: intl.get("openExternal"),
|
||||||
iconProps: { iconName: "NavigateExternalInline" },
|
iconProps: { iconName: "NavigateExternalInline" },
|
||||||
onClick: (e) => {
|
onClick: (e) => {
|
||||||
if (window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey) {
|
if (platformCtrl(e)) {
|
||||||
window.utils.imageCallback(ImageCallbackTypes.OpenExternalBg)
|
window.utils.imageCallback(ImageCallbackTypes.OpenExternalBg)
|
||||||
} else {
|
} else {
|
||||||
window.utils.imageCallback(ImageCallbackTypes.OpenExternal)
|
window.utils.imageCallback(ImageCallbackTypes.OpenExternal)
|
||||||
|
@ -12,7 +12,7 @@ export type FeedProps = FeedReduxProps & {
|
|||||||
items: RSSItem[]
|
items: RSSItem[]
|
||||||
sourceMap: Object
|
sourceMap: Object
|
||||||
keyword: string
|
keyword: string
|
||||||
shortcuts: (item: RSSItem, key: string) => void
|
shortcuts: (item: RSSItem, e: KeyboardEvent) => void
|
||||||
markRead: (item: RSSItem) => void
|
markRead: (item: RSSItem) => void
|
||||||
contextMenu: (feedId: string, item: RSSItem, e) => void
|
contextMenu: (feedId: string, item: RSSItem, e) => void
|
||||||
loadMore: (feed: RSSFeed) => void
|
loadMore: (feed: RSSFeed) => void
|
||||||
|
@ -28,7 +28,7 @@ const makeMapStateToProps = () => {
|
|||||||
|
|
||||||
const mapDispatchToProps = (dispatch: AppDispatch) => {
|
const mapDispatchToProps = (dispatch: AppDispatch) => {
|
||||||
return {
|
return {
|
||||||
shortcuts: (item: RSSItem, key: string) => dispatch(itemShortcuts(item, key)),
|
shortcuts: (item: RSSItem, e: KeyboardEvent) => dispatch(itemShortcuts(item, e)),
|
||||||
dismiss: () => dispatch(dismissItem()),
|
dismiss: () => dispatch(dismissItem()),
|
||||||
offsetItem: (offset: number) => dispatch(showOffsetItem(offset)),
|
offsetItem: (offset: number) => dispatch(showOffsetItem(offset)),
|
||||||
toggleHasRead: (item: RSSItem) => dispatch(item.hasRead ? markUnread(item) : markRead(item)),
|
toggleHasRead: (item: RSSItem) => dispatch(item.hasRead ? markUnread(item) : markRead(item)),
|
||||||
|
@ -33,7 +33,7 @@ const makeMapStateToProps = () => {
|
|||||||
}
|
}
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
shortcuts: (item: RSSItem, key: string) => dispatch(itemShortcuts(item, key)),
|
shortcuts: (item: RSSItem, e: KeyboardEvent) => dispatch(itemShortcuts(item, e)),
|
||||||
markRead: (item: RSSItem) => dispatch(markRead(item)),
|
markRead: (item: RSSItem) => dispatch(markRead(item)),
|
||||||
contextMenu: (feedId: string, item: RSSItem, e) => dispatch(openItemMenu(item, feedId, e)),
|
contextMenu: (feedId: string, item: RSSItem, e) => dispatch(openItemMenu(item, feedId, e)),
|
||||||
loadMore: (feed: RSSFeed) => dispatch(loadMore(feed)),
|
loadMore: (feed: RSSFeed) => dispatch(loadMore(feed)),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as db from "../db"
|
import * as db from "../db"
|
||||||
import intl from "react-intl-universal"
|
import intl from "react-intl-universal"
|
||||||
import { domParser, htmlDecode, ActionStatus, AppThunk } from "../utils"
|
import { domParser, htmlDecode, ActionStatus, AppThunk, platformCtrl } from "../utils"
|
||||||
import { RSSSource } from "./source"
|
import { RSSSource } from "./source"
|
||||||
import { FeedActionTypes, INIT_FEED, LOAD_MORE, FilterType, initFeeds } from "./feed"
|
import { FeedActionTypes, INIT_FEED, LOAD_MORE, FilterType, initFeeds } from "./feed"
|
||||||
import Parser from "@yang991178/rss-parser"
|
import Parser from "@yang991178/rss-parser"
|
||||||
@ -331,21 +331,22 @@ export function toggleHidden(item: RSSItem): AppThunk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function itemShortcuts(item: RSSItem, key: string): AppThunk {
|
export function itemShortcuts(item: RSSItem, e: KeyboardEvent): AppThunk {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
switch (key) {
|
switch (e.key) {
|
||||||
case "m": case "M":
|
case "m": case "M":
|
||||||
if (item.hasRead) dispatch(markUnread(item))
|
if (item.hasRead) dispatch(markUnread(item))
|
||||||
else dispatch(markRead(item))
|
else dispatch(markRead(item))
|
||||||
break
|
break
|
||||||
case "b": case "B":
|
case "b": case "B":
|
||||||
if (!item.hasRead) dispatch(markRead(item))
|
if (!item.hasRead) dispatch(markRead(item))
|
||||||
window.utils.openExternal(item.link)
|
window.utils.openExternal(item.link, platformCtrl(e))
|
||||||
break
|
break
|
||||||
case "s": case "S":
|
case "s": case "S":
|
||||||
dispatch(toggleStarred(item))
|
dispatch(toggleStarred(item))
|
||||||
break
|
break
|
||||||
case "h": case "H":
|
case "h": case "H":
|
||||||
|
if (!item.hasRead) dispatch(markRead(item))
|
||||||
dispatch(toggleHidden(item))
|
dispatch(toggleHidden(item))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,6 @@ function insertSource(source: RSSSource): AppThunk<Promise<RSSSource>> {
|
|||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addSource(url: string, name: string = null, batch = false): AppThunk<Promise<number>> {
|
export function addSource(url: string, name: string = null, batch = false): AppThunk<Promise<number>> {
|
||||||
|
@ -189,3 +189,7 @@ export function validateRegex(regex: string, flags = ""): RegExp {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function platformCtrl(e: React.MouseEvent | React.KeyboardEvent | MouseEvent | KeyboardEvent) {
|
||||||
|
return window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user