DarkArtheme

app.jsx

May 6th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. import React from "react";
  2.  
  3.  
  4. //Импорт красивых сберовских кнопочек
  5. import { IconHeart } from '@sberdevices/plasma-icons';
  6. import { Button } from '@sberdevices/plasma-ui';
  7.  
  8. import {
  9. createSmartappDebugger,
  10. createAssistant,
  11. } from "@sberdevices/assistant-client";
  12.  
  13. import styles from "./App.css";
  14. import Video from "./Video"
  15.  
  16.  
  17. const initializeAssistant = (getState/*: any*/) => {
  18. if (process.env.NODE_ENV === "development") {
  19. return createSmartappDebugger({
  20. token: process.env.REACT_APP_TOKEN ?? "",
  21. initPhrase: `Запусти ${process.env.REACT_APP_SMARTAPP}`,
  22. getState,
  23. });
  24. }
  25. return createAssistant({ getState });
  26. };
  27.  
  28.  
  29.  
  30. export class App extends React.Component {
  31.  
  32. constructor(props) {
  33. super(props);
  34. console.log('constructor');
  35.  
  36. this.state = {
  37. notes: [],
  38. // testField: 0,
  39. // videoURLs: [
  40. // { url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstleyVEVO", id : 1 },
  41. // { url: "https://www.youtube.com/watch?v=L_jWHffIx5E&ab_channel=SmashMouthVEVO", id : 2 }
  42. // ]
  43. }
  44.  
  45. this.assistant = initializeAssistant(() => this.getStateForAssistant() );
  46. // this.assistant.on("data", (event/*: any*/) => {
  47. // console.log(`assistant.on(data)`, event);
  48. // const { action } = event
  49. // this.dispatchAssistantAction(action);
  50. // });
  51. this.assistant.on("start", (event) => {
  52. console.log(`assistant.on(start)`, event);
  53. });
  54.  
  55. }
  56.  
  57. componentDidMount() {
  58. console.log('componentDidMount');
  59. }
  60.  
  61. getStateForAssistant () {
  62. console.log('getStateForAssistant: this.state:', this.state)
  63. const state = {
  64. item_selector: {
  65. items: this.state.notes.map(
  66. ({ id, title }, index) => ({
  67. number: index + 1,
  68. id,
  69. title,
  70. })
  71. ),
  72. },
  73. };
  74. console.log('getStateForAssistant: state:', state)
  75. return state;
  76. }
  77.  
  78. // dispatchAssistantAction (action) {
  79. // console.log('dispatchAssistantAction', action);
  80. // if (action) {
  81. // switch (action.type) {
  82. // default:
  83. // throw new Error();
  84. // }
  85. // }
  86. // }
  87.  
  88.  
  89.  
  90. // handleClick = (e) => {
  91. // this.setState ((state) => ({
  92. // testField: state.testField + 1,
  93. // }));
  94. // }
  95.  
  96.  
  97. render() {
  98. console.log('render');
  99. const testStyle = {
  100. margin: "20px",
  101. color: "pink",
  102. }
  103. return (
  104. <div className={styles.main}>
  105. <div className="videos">
  106. {/* <h1 style={testStyle}>Just random text</h1>
  107. <p style={testStyle}>Here we can see the value in testField (number of likes): { this.state.testField }</p>
  108. <Video videos={this.state.videoURLs} /> */}
  109. </div>
  110. {/* <div className="button">
  111. <Button
  112. contentLeft={<IconHeart color="green" size="s" />}
  113. text={"like"}
  114. view={"primary"}
  115. outlined={"true"}
  116. onClick={this.handleClick}>
  117. </Button>
  118. </div> */}
  119. </div>
  120. )
  121. }
  122.  
  123.  
  124. }
  125.  
  126.  
Advertisement
Add Comment
Please, Sign In to add comment