From d9aa49dbc3c5cba107fa4ef222199b1c13fe6a1b Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Tue, 13 Nov 2018 11:15:23 +0100 Subject: [PATCH] Implement window titles, add default tasks window --- .../window-manager/floating-window-area.jsx | 2 +- .../components/window-manager/sidebar.jsx | 2 +- src/client/components/window/index.jsx | 6 ++++ .../components/window/window-title-context.js | 5 +++ src/client/components/window/window-title.jsx | 12 +++++++ src/client/components/{ => window}/window.jsx | 21 +++++++----- src/client/index.jsx | 11 +++++++ src/client/router.js | 8 ++++- src/client/stores/windows.js | 3 +- src/client/views/node/create.jsx | 33 +++++++++++-------- src/client/views/tasks.jsx | 14 ++++++++ 11 files changed, 91 insertions(+), 26 deletions(-) create mode 100644 src/client/components/window/index.jsx create mode 100644 src/client/components/window/window-title-context.js create mode 100644 src/client/components/window/window-title.jsx rename src/client/components/{ => window}/window.jsx (79%) create mode 100644 src/client/views/tasks.jsx diff --git a/src/client/components/window-manager/floating-window-area.jsx b/src/client/components/window-manager/floating-window-area.jsx index 9e3bc7e..b94c146 100644 --- a/src/client/components/window-manager/floating-window-area.jsx +++ b/src/client/components/window-manager/floating-window-area.jsx @@ -30,7 +30,7 @@ module.exports = function FloatingWindowArea({windows, onStartMove, onStartCorne }; return ( - + ); }) ); diff --git a/src/client/components/window-manager/sidebar.jsx b/src/client/components/window-manager/sidebar.jsx index e058dee..387ed10 100644 --- a/src/client/components/window-manager/sidebar.jsx +++ b/src/client/components/window-manager/sidebar.jsx @@ -66,7 +66,7 @@ module.exports = function Sidebar({elementRef, side, windows, onMouseOver, onMou }; return ( - + ); })} diff --git a/src/client/components/window/index.jsx b/src/client/components/window/index.jsx new file mode 100644 index 0000000..688e17e --- /dev/null +++ b/src/client/components/window/index.jsx @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + Window: require("./window"), + Title: require("./window-title") +}; diff --git a/src/client/components/window/window-title-context.js b/src/client/components/window/window-title-context.js new file mode 100644 index 0000000..ea79e0e --- /dev/null +++ b/src/client/components/window/window-title-context.js @@ -0,0 +1,5 @@ +"use strict"; + +const React = require("react"); + +module.exports = React.createContext(() => {}); diff --git a/src/client/components/window/window-title.jsx b/src/client/components/window/window-title.jsx new file mode 100644 index 0000000..cadb782 --- /dev/null +++ b/src/client/components/window/window-title.jsx @@ -0,0 +1,12 @@ +"use strict"; + +const React = require("react"); + +const windowTitleContext = require("./window-title-context"); + +module.exports = function WindowTitle({children}) { + let reporter = React.useContext(windowTitleContext); + reporter(children); + + return null; +}; diff --git a/src/client/components/window.jsx b/src/client/components/window/window.jsx similarity index 79% rename from src/client/components/window.jsx rename to src/client/components/window/window.jsx index cb15eb1..90f8f35 100644 --- a/src/client/components/window.jsx +++ b/src/client/components/window/window.jsx @@ -4,7 +4,8 @@ const React = require("react"); const createReactClass = require("create-react-class"); const classnames = require("classnames"); -const renderIf = require("../util/render-if"); +const renderIf = require("../../util/render-if"); +const windowTitleContext = require("./window-title-context"); function cancelEvent(event) { /* NOTE: This is used on mousedown events for controls like the CloseButton, to ensure that a click-and-drag on a titlebar control cannot start a window drag operation. */ @@ -78,17 +79,21 @@ function Resizer({onMouseDown}) { } module.exports = function Window({elementRef, style, window: window_, onMouseDown, onTitleMouseDown, onClose, onResizerMouseDown}) { + let [windowTitle, setWindowTitle] = React.useState(""); + return (
- + -
-
- {window_.contents} -
+ +
+
+ {window_.contents} +
- {renderIf(window_.resizable, )} -
+ {renderIf(window_.resizable, )} +
+
); }; diff --git a/src/client/index.jsx b/src/client/index.jsx index f8dadb9..3bf5564 100644 --- a/src/client/index.jsx +++ b/src/client/index.jsx @@ -86,6 +86,16 @@ let App = createReactClass({ }) }; }, + componentDidMount: function () { + this.onAction({ + type: "open", + path: "/tasks", + options: { + sidebar: "right", + height: 380 + } + }); + }, onAction: function (action) { if (action.type === "open") { this.state.windows.add({ @@ -95,6 +105,7 @@ let App = createReactClass({ initialX: defaultValue(action.options.x, 20), initialY: defaultValue(action.options.y, 100), resizable: defaultValue(action.options.resizable, true), + sidebar: action.options.sidebar, contents: }); } else if (action.type === "notify") { diff --git a/src/client/router.js b/src/client/router.js index 615c292..41c82fd 100644 --- a/src/client/router.js +++ b/src/client/router.js @@ -6,6 +6,8 @@ const React = require("react"); const createRouter = require("./hybrid-router"); const ViewManager = require("./components/view-manager"); +const TasksView = require("./views/tasks"); + function PageOne({foo}) { return (
@@ -39,7 +41,7 @@ function SubmittedForm({data}) { let router = createRouter(); router.get("/actions/create-new-node", (req, res) => { - res.open("/"); + res.open("/node/create"); }); router.get("/node/create", (req, res) => { @@ -64,6 +66,10 @@ router.get("/", (req, res) => { }); }); +router.get("/tasks", (req, res) => { + res.render(TasksView); +}); + router.get("/page2", (req, res) => { res.render(PageTwo, { foo: "baz" diff --git a/src/client/stores/windows.js b/src/client/stores/windows.js index 9098208..dd1affa 100644 --- a/src/client/stores/windows.js +++ b/src/client/stores/windows.js @@ -53,7 +53,8 @@ module.exports = function createWindowStore({onUpdated}) { userX: 0, userY: 0, width: window_.initialWidth, - height: window_.initialHeight + height: window_.initialHeight, + sidebar: window_.sidebar })); updateWindowIndexes(); diff --git a/src/client/views/node/create.jsx b/src/client/views/node/create.jsx index 445a9eb..163b718 100644 --- a/src/client/views/node/create.jsx +++ b/src/client/views/node/create.jsx @@ -2,6 +2,8 @@ const React = require("react"); +const Window = require("../../components/window"); + // const { Form, Field, Label, TextInput, Section } = require("../components/form"); function Form(opts) { @@ -31,19 +33,22 @@ function Section(opts) { module.exports = function CreateNode() { return ( -
- - - - - - - - - -
- -
-
+
+ Create new node +
+ + + + + + + + + +
+ +
+
+
); }; diff --git a/src/client/views/tasks.jsx b/src/client/views/tasks.jsx new file mode 100644 index 0000000..abf49cf --- /dev/null +++ b/src/client/views/tasks.jsx @@ -0,0 +1,14 @@ +"use strict"; + +const React = require("react"); + +const Window = require("../components/window"); + +module.exports = function TasksView() { + return ( +
+ Tasks + Tasks go here +
+ ); +};