差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
| tutorial_3 [2022/01/05 10:42] – [第四項 Reactについて] satoshi | tutorial_3 [2022/01/05 10:49] (現在) – [第四項 Reactについて] satoshi | ||
|---|---|---|---|
| 行 265: | 行 265: | ||
| 等から学び始めることがよいでしょう。\\ | 等から学び始めることがよいでしょう。\\ | ||
| - | ただし今回はReact自体が分からなくても、どのプログラムファイルをどういじれば何が変わるかという点だけでピンポイントで解説していこうと思いますので、本チュートリアルを進めるうえではReactの学習は必須ではありません。\\ | + | ただし今回はReact自体が分からなくても、どのプログラムファイルをどういじれば何が変わるかという点だけでピンポイントで上級編の一環として解説していこうと思いますので、本チュートリアルを進めるうえではReactの学習は必須ではありません。\\ |
| - | 参考までにエリアを設定するページのコードを貼付します。 | ||
| - | <sxh Typescript; | ||
| - | import React, { useState, useCallback, | ||
| - | |||
| - | import { | ||
| - | LineUI, | ||
| - | LineReducer, | ||
| - | LineSetContext, | ||
| - | Button, | ||
| - | } from ' | ||
| - | |||
| - | import Sidebar, { SidebarBox, SidebarHeading, | ||
| - | import {Layout, Content, MainContainer} from ' | ||
| - | |||
| - | |||
| - | const Camareas: React.FC< | ||
| - | const [error, setError] = useState< | ||
| - | const [showDelete, | ||
| - | const [state, dispatch] = useReducer(LineReducer, | ||
| - | const HOSTNAME = window.location.hostname; | ||
| - | const imgsrc = ' | ||
| - | const fetchAreas = useCallback(async () => { | ||
| - | try { | ||
| - | const response = await fetch('/ | ||
| - | if (!response.ok) { | ||
| - | throw await response.json(); | ||
| - | } | ||
| - | const {areas} = await response.json(); | ||
| - | |||
| - | dispatch({ | ||
| - | type: ' | ||
| - | state: areas | ||
| - | }); | ||
| - | } catch (error) { | ||
| - | setError(' | ||
| - | } | ||
| - | },[]); | ||
| - | |||
| - | const saveAreas = useCallback(async () => { | ||
| - | try { | ||
| - | const response = await fetch('/ | ||
| - | method: ' | ||
| - | body: JSON.stringify({ | ||
| - | areas: state | ||
| - | }), | ||
| - | headers: { | ||
| - | ' | ||
| - | } | ||
| - | }); | ||
| - | if (!response.ok) { | ||
| - | throw await response.json(); | ||
| - | } | ||
| - | |||
| - | } catch (error) { | ||
| - | setError(' | ||
| - | } | ||
| - | |||
| - | },[ state ]); | ||
| - | |||
| - | const addArea = useCallback(async () => { | ||
| - | dispatch({ | ||
| - | type: ' | ||
| - | data: { | ||
| - | points: [ | ||
| - | {" | ||
| - | {" | ||
| - | {" | ||
| - | {" | ||
| - | ] | ||
| - | } | ||
| - | }); | ||
| - | },[]); | ||
| - | |||
| - | const removeArea = useCallback(async (index) => { | ||
| - | dispatch({ | ||
| - | type: ' | ||
| - | index | ||
| - | }); | ||
| - | },[]); | ||
| - | |||
| - | const addPoint = useCallback(async (index) => { | ||
| - | dispatch({ | ||
| - | type: ' | ||
| - | index | ||
| - | }); | ||
| - | },[]); | ||
| - | |||
| - | const removePoint = useCallback(async (index) => { | ||
| - | if(state[index].points.length <= 3) return; | ||
| - | dispatch({ | ||
| - | type: ' | ||
| - | index | ||
| - | }); | ||
| - | },[state]); | ||
| - | |||
| - | useEffect(()=> | ||
| - | fetchAreas(); | ||
| - | }, [fetchAreas]); | ||
| - | |||
| - | return ( | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | </ | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | </ | ||
| - | |||
| - | { | ||
| - | state.map((_shape, | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | <Button size=' | ||
| - | : | ||
| - | <> | ||
| - | <Button size=' | ||
| - | <Button size=' | ||
| - | </>} | ||
| - | </ | ||
| - | </ | ||
| - | ) | ||
| - | } | ||
| - | < | ||
| - | <Button size=' | ||
| - | </ | ||
| - | < | ||
| - | < | ||
| - | <Button size=' | ||
| - | <Button size=' | ||
| - | </ | ||
| - | </ | ||
| - | < | ||
| - | <input type=' | ||
| - | <label htmlFor=' | ||
| - | </ | ||
| - | </ | ||
| - | < | ||
| - | < | ||
| - | {error && < | ||
| - | < | ||
| - | < | ||
| - | </ | ||
| - | </ | ||
| - | </ | ||
| - | </ | ||
| - | ); | ||
| - | }; | ||
| - | |||
| - | export default Camareas; | ||
| - | |||
| - | </ | ||
| ===== 第五項 WEBサーバーの解説===== | ===== 第五項 WEBサーバーの解説===== | ||
| WEBサーバーについては今回FlaskというPythonで簡単にWEBサーバーを構築できる仕組みを採用します。\\ | WEBサーバーについては今回FlaskというPythonで簡単にWEBサーバーを構築できる仕組みを採用します。\\ | ||