-
Notifications
You must be signed in to change notification settings - Fork 1
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
18 changed files
with
221 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { TypedAction } from "redoodle"; | ||
|
||
export namespace BannerActions { | ||
export const set = TypedAction.define("banner::set")<string | undefined>(); | ||
} | ||
|
||
export namespace BannerInternalActions { | ||
export const set = TypedAction.define("banner-internal::set")<string | undefined>(); | ||
} |
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,7 @@ | ||
.banner-info-banner { | ||
// can't text-align:center :( | ||
// https://github.com/palantir/blueprint/issues/2021#issuecomment-393744854 | ||
text-align: left; | ||
display: flex; | ||
justify-content: center; | ||
} |
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,75 @@ | ||
import { EditableText } from "@blueprintjs/core"; | ||
import React, { useCallback, useState } from "react"; | ||
import { connect } from "react-redux"; | ||
import { BannerActions } from "../../actions/bannerActions"; | ||
import { selectBannerValue } from "../../selectors/bannerSelectors"; | ||
import { RootState } from "../../states/rootState"; | ||
import { InfoBanner } from "../../views/notes/components/InfoBanner"; | ||
import "./Banner.scss"; | ||
|
||
export namespace Banner { | ||
export interface StoreProps { | ||
value: string | undefined; | ||
} | ||
|
||
export interface DispatchProps { | ||
setBanner: typeof BannerActions.set; | ||
} | ||
|
||
export type Props = StoreProps & DispatchProps; | ||
|
||
export interface State { | ||
inputValue: string; | ||
} | ||
} | ||
|
||
const BannerInternal = React.memo((props: Banner.Props) => { | ||
if (props.value == null) { | ||
return null; | ||
} | ||
|
||
const [inputValue, setInputValue] = useState<string>(props.value); | ||
|
||
const handleChange = useCallback((value: string) => { | ||
setInputValue(value); | ||
}, []); | ||
|
||
const handleConfirm = useCallback((value: string) => { | ||
const trimmedValue = value.trim(); | ||
if (trimmedValue.length === 0) { | ||
props.setBanner(undefined); | ||
} else { | ||
props.setBanner(trimmedValue); | ||
} | ||
}, []); | ||
|
||
const swallowKeyDown = useCallback((evt: React.KeyboardEvent) => { | ||
if (evt.key === "Enter") { | ||
evt.stopPropagation(); | ||
evt.nativeEvent.stopPropagation(); | ||
evt.nativeEvent.stopImmediatePropagation(); | ||
evt.preventDefault(); | ||
console.log(evt.key); | ||
} | ||
}, []); | ||
|
||
const input = ( | ||
<div onKeyDown={swallowKeyDown}> | ||
<EditableText value={inputValue} onChange={handleChange} onConfirm={handleConfirm} /> | ||
</div> | ||
); | ||
return <InfoBanner className="banner-info-banner" value={input} />; | ||
}); | ||
|
||
function mapStateToProps(state: RootState): Banner.StoreProps { | ||
return { | ||
value: selectBannerValue(state) | ||
}; | ||
} | ||
|
||
const mapDispatchToProps: Banner.DispatchProps = { | ||
setBanner: BannerActions.set | ||
}; | ||
|
||
const enhance = connect(mapStateToProps, mapDispatchToProps); | ||
export const Banner = enhance(BannerInternal); |
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,47 @@ | ||
import classNames from "classnames"; | ||
import React, { useCallback } from "react"; | ||
import { connect } from "react-redux"; | ||
import { BannerActions } from "../../actions/bannerActions"; | ||
import { selectBannerHasValue } from "../../selectors/bannerSelectors"; | ||
import { RootState } from "../../states/rootState"; | ||
|
||
export namespace BannerMenuItem { | ||
export interface StoreProps { | ||
hasValue: boolean; | ||
} | ||
|
||
export interface DispatchProps { | ||
setBanner: typeof BannerActions.set; | ||
} | ||
|
||
export type Props = StoreProps & DispatchProps; | ||
} | ||
|
||
const BannerMenuItemInternal = React.memo((props: BannerMenuItem.Props) => { | ||
if (props.hasValue) { | ||
return null; | ||
} | ||
|
||
const handleClick = useCallback(() => { | ||
props.setBanner("<CLICK AND CHANGE ME // EMPTY BANNER REMOVES IT>"); | ||
}, []); | ||
|
||
return ( | ||
<span className={classNames("top-menu-item", "banner-menu-item")} onClick={handleClick}> | ||
SET BANNER | ||
</span> | ||
); | ||
}); | ||
|
||
function mapStateToProps(state: RootState): BannerMenuItem.StoreProps { | ||
return { | ||
hasValue: selectBannerHasValue(state) | ||
}; | ||
} | ||
|
||
const mapDispatchToProps: BannerMenuItem.DispatchProps = { | ||
setBanner: BannerActions.set | ||
}; | ||
|
||
const enhance = connect(mapStateToProps, mapDispatchToProps); | ||
export const BannerMenuItem = enhance(BannerMenuItemInternal); |
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,9 @@ | ||
import { setWith, TypedReducer } from "redoodle"; | ||
import { BannerInternalActions } from "../actions/bannerActions"; | ||
import { BannerState } from "../states/bannerState"; | ||
|
||
export const bannerReducer = TypedReducer.builder<BannerState>() | ||
.withHandler(BannerInternalActions.set.TYPE, (state, value) => { | ||
return setWith(state, { value }); | ||
}) | ||
.build(); |
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,34 @@ | ||
import { ipcRenderer } from "electron-better-ipc"; | ||
import { TypedAction } from "redoodle"; | ||
import { all, put, takeEvery } from "redux-saga/effects"; | ||
import { IpcEvent } from "../../shared/ipcEvent"; | ||
import { BannerActions, BannerInternalActions } from "../actions/bannerActions"; | ||
|
||
const BANNER_FILE_NAME = "banner"; | ||
|
||
export function* bannerSaga() { | ||
yield initializeBanner(); | ||
yield all([yield takeEvery(BannerActions.set.TYPE, setBanner)]); | ||
} | ||
|
||
function* initializeBanner() { | ||
const banner: string | undefined = yield ipcRenderer.callMain( | ||
IpcEvent.READ_DATA, | ||
BANNER_FILE_NAME | ||
); | ||
|
||
yield put(BannerInternalActions.set(banner)); | ||
} | ||
|
||
function* setBanner(action: TypedAction<string | undefined>) { | ||
const banner = action.payload; | ||
yield put(BannerInternalActions.set(banner)); | ||
writeBanner(banner); | ||
} | ||
|
||
function writeBanner(banner: string | undefined) { | ||
ipcRenderer.callMain(IpcEvent.WRITE_DATA, { | ||
fileName: BANNER_FILE_NAME, | ||
data: banner | ||
}); | ||
} |
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,4 @@ | ||
import { RootState } from "../states/rootState"; | ||
|
||
export const selectBannerValue = (state: RootState) => state.banner.value; | ||
export const selectBannerHasValue = (state: RootState) => state.banner.value != null; |
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,9 @@ | ||
export interface BannerState { | ||
value: string | undefined; | ||
} | ||
|
||
export function createInitialBannerState(): BannerState { | ||
return { | ||
value: undefined | ||
}; | ||
} |
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