procon_bypass_man-web 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ import React, { useState, useReducer } from "react";
2
+ import { Button, buttons } from "../types/button";
3
+ import { ModalProps } from "../components/buttons_modal";
4
+
5
+ export type ModalSetting = {
6
+ toggleModal: any;
7
+ setCallbackOnSubmit: any;
8
+ setCallbackOnClose: any;
9
+ setTitle: any;
10
+ setPrefillButtons: any;
11
+ }
12
+
13
+ type openModalParams = {
14
+ title: string,
15
+ prefill: any,
16
+ callbackOnSubmit: any,
17
+ };
18
+
19
+ export const useModal = () => {
20
+ const [visible, toggleModal] = useReducer(((m: boolean) => { return !m; }), false);
21
+ const [callbackOnSubmit, setCallbackOnSubmit] = useState(undefined as any)
22
+ const [callbackOnClose, setCallbackOnClose] = useState(undefined as any)
23
+ const [title, setTitle] = useState("")
24
+ const [prefill, setPrefillButtons] = useState<Array<Button>>([])
25
+
26
+ const openModal = ({ title, prefill, callbackOnSubmit }: openModalParams): void => {
27
+ toggleModal();
28
+ setTitle(title)
29
+ setPrefillButtons(prefill);
30
+ setCallbackOnSubmit(() => callbackOnSubmit);
31
+ setCallbackOnClose(() => toggleModal);
32
+ }
33
+ const modalProps: ModalProps = { visible, callbackOnSubmit, callbackOnClose, title, prefill };
34
+ const modalSetting: ModalSetting ={ toggleModal, setCallbackOnSubmit, setCallbackOnClose, setTitle, setPrefillButtons };
35
+
36
+ return [modalProps, openModal] as const;
37
+ }
@@ -13,6 +13,8 @@ import { ButtonsSettingContext, } from "./../contexts/buttons_setting";
13
13
  import { ButtonsSettingConverter } from "./../lib/buttons_setting_converter";
14
14
  import { disableFlipType, alwaysFlipType, flipIfPressedSelfType, flipIfPressedSomeButtonsType, ignoreButtonsInFlipingType, remapType, closeMenuType, applyMacroType, installMacroType, installModeType, applyModeType } from "../reducers/layer_reducer";
15
15
  import { ButtonsModal } from "../components/buttons_modal";
16
+ import { useModal, ModalSetting } from "../hooks/useModal";
17
+ import { ModalProps } from "../components/buttons_modal";
16
18
  import { InstallableMacros } from "../components/installable_macros";
17
19
  import { InstallableModes } from "../components/installable_modes";
18
20
  import _ from 'lodash';
@@ -31,6 +33,7 @@ export const ButtonsSettingPage = () => {
31
33
  const layerRefs = layerKeys.map((l) => ({} as LayerRef));
32
34
  const [initializedSetting, setInitializedSetting] = useState({} as ButtonsSettingType)
33
35
  const [infoMessage, setInfoMessage] = useState(undefined as undefined | string)
36
+ const [modalProps, openModal] = useModal();
34
37
 
35
38
  const switchLayer = (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
36
39
  if (event.target instanceof HTMLElement) {
@@ -218,22 +221,12 @@ export const ButtonsSettingPage = () => {
218
221
  return "inactive"
219
222
  };
220
223
  }
224
+
221
225
  const handlePrefixKeysField = () => {
222
- toggleModal();
223
- setModalTitle("キープレフィックスの変更")
224
- setModalPrefillButtons(prefixKeys);
225
- setModalCallbackOnSubmit(() => setPrefixKeys);
226
- setModalCloseCallback(() => toggleModal);
226
+ openModal({ title: "キープレフィックスの変更", prefill: prefixKeys, callbackOnSubmit: setPrefixKeys });
227
227
  }
228
228
 
229
- // for modal
230
- const [isOpenModal, toggleModal] = useReducer(((m) => { return !m; }), false);
231
- const [modalCallbackOnSubmit, setModalCallbackOnSubmit] = useState(undefined as any)
232
- const [modalCloseCallback, setModalCloseCallback] = useState(undefined as any)
233
- const [modalTitle, setModalTitle] = useState("")
234
- const [modalPrefillButtons, setModalPrefillButtons] = useState<Array<Button>>([])
235
-
236
- if(!loaded) { return null; };
229
+ if(!loaded) { return <div>{infoMessage}</div> };
237
230
 
238
231
  return(
239
232
  <>
@@ -244,19 +237,16 @@ export const ButtonsSettingPage = () => {
244
237
  <a href="#" onClick={exportSetting}>エクスポートする</a>
245
238
  </div>
246
239
 
247
- <h3>インストール可能なマクロ</h3>
248
- {<InstallableMacros />}
249
-
250
240
  <h3>インストール可能なモード</h3>
251
241
  {<InstallableModes />}
252
242
 
253
243
  <h3>インストール可能なマクロ</h3>
254
- {loaded && <InstallableMacros />}
244
+ {<InstallableMacros />}
255
245
 
256
246
  <h3>設定中のプレフィックスキー</h3>
257
247
  <div css={css`position: relative; margin-bottom: 20px;`}>
258
248
  <input type="text" value={prefixKeys.join(", ")} readOnly={true} onClick={handlePrefixKeysField} />
259
- {isOpenModal && <ButtonsModal callbackOnSubmit={modalCallbackOnSubmit} callbackOnClose={modalCloseCallback} title={modalTitle} prefill={modalPrefillButtons} positionOnShown={"stay"} />}
249
+ {<ButtonsModal {...modalProps as ModalProps} />}
260
250
  </div>
261
251
  </div>
262
252
  <div css={css`display: table-cell`}>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procon_bypass_man-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiikko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-16 00:00:00.000000000 Z
11
+ date: 2021-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -62,6 +62,7 @@ files:
62
62
  - ".babelrc"
63
63
  - ".circleci/config.yml"
64
64
  - ".gitignore"
65
+ - ".node-version"
65
66
  - ".rspec"
66
67
  - ".rubocop.yml"
67
68
  - CHANGELOG.md
@@ -76,8 +77,10 @@ files:
76
77
  - bin/setup
77
78
  - jest.config.ts
78
79
  - lib/procon_bypass_man/web.rb
80
+ - lib/procon_bypass_man/web/configuration.rb
79
81
  - lib/procon_bypass_man/web/db.rb
80
82
  - lib/procon_bypass_man/web/migration/001_create_settings_table.sql
83
+ - lib/procon_bypass_man/web/migration/002_insert_default_settings_rows.sql
81
84
  - lib/procon_bypass_man/web/models/base_model.rb
82
85
  - lib/procon_bypass_man/web/models/setting.rb
83
86
  - lib/procon_bypass_man/web/public/bundle.js
@@ -85,6 +88,8 @@ files:
85
88
  - lib/procon_bypass_man/web/public/index.html
86
89
  - lib/procon_bypass_man/web/server.rb
87
90
  - lib/procon_bypass_man/web/setting_parser.rb
91
+ - lib/procon_bypass_man/web/setting_parser/layer.rb
92
+ - lib/procon_bypass_man/web/setting_parser/top_level_layer.rb
88
93
  - lib/procon_bypass_man/web/storage.rb
89
94
  - lib/procon_bypass_man/web/version.rb
90
95
  - package.json
@@ -98,6 +103,7 @@ files:
98
103
  - src/components/macro_settings.tsx
99
104
  - src/components/mode_settings.tsx
100
105
  - src/contexts/buttons_setting.ts
106
+ - src/hooks/useModal.ts
101
107
  - src/index.html
102
108
  - src/lib/button_state.test.ts
103
109
  - src/lib/button_state.ts