Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import connect from '@vkontakte/vkui-connect';
  3. import { View, Alert } from '@vkontakte/vkui';
  4. import '@vkontakte/vkui/dist/vkui.css';
  5. import ReactDOM from 'react-dom';
  6. import {CopyToClipboard} from 'react-copy-to-clipboard';
  7.  
  8. import Home from './panels/Home';
  9. import Persik from './panels/Persik';
  10. import Game from './panels/Game';
  11. import MapView from './panels/MapView';
  12. import VKCoin from './panels/VKCoin';
  13. import Usites from './panels/Usites';
  14. import Settings from './panels/Settings';
  15. import Flash from './panels/Flash';
  16.  
  17. class App extends React.Component {
  18.     constructor(props) {
  19.         super(props);
  20.  
  21.         this.state = {
  22.             activePanel: 'home',
  23.             fetchedUser: null,
  24.             popout: null,
  25.             header: null,
  26.         };
  27.         this.closePopout = this.closePopout.bind(this);
  28.     };
  29.  
  30.     componentDidMount() {
  31.         connect.subscribe((e) => {
  32.             switch (e.detail.type) {
  33.                 case 'VKWebAppGetUserInfoResult':
  34.                 this.setState({ fetchedUser: e.detail.data, activePanel: 'home' });
  35.                 break;
  36.                     case 'VKWebAppShowWallPostBoxResult':
  37.                     this.openPopout()
  38.                     break;
  39.                 case 'VKWebAppAddToCommunityResult':
  40.                 this.openPopout2()
  41.                 break;
  42.                
  43.                 case 'VKWebAppFlashGetInfoResult': 
  44.               this.openPopout3()
  45.               break;
  46.                    
  47.                    
  48.                 default:
  49.                     console.log(e.detail.type);
  50.             }
  51.         });
  52.         connect.send('VKWebAppGetUserInfo', {});
  53.     };
  54.  
  55.     go = (e) => {
  56.         this.setState({ activePanel: e.currentTarget.dataset.to })
  57.     };
  58.  
  59.     share = () => {
  60.         connect.send("VKWebAppShowWallPostBox", {"message": "@devbg, участвую! #1multiapp"});
  61.       };
  62.    
  63.     flasgetinfo = () => {
  64.         connect.send("VKWebAppFlashGetInfo");
  65.       };
  66.     flashlevel1 = () => {
  67.       connect.send("VKWebAppFlashSetLevel", {"level": 1});
  68.       };
  69.     addtocomm = () => {
  70.       connect.send("VKWebAppAddToCommunity", {});
  71.     };
  72.     flashlevel0 = () => {
  73.       connect.send("VKWebAppFlashSetLevel", {"level": 0});
  74.       };
  75.    
  76.     openPopout = () => {
  77.         this.setState({ popout:
  78.           <Alert
  79.             actions={[{
  80.               title: 'Ок',
  81.               autoclose: true,
  82.               style: 'destructive'
  83.             }]}
  84.             onClose={this.closePopout}
  85.           >
  86.             <h2>Поздравляем Вас!</h2>
  87.             <p>Мы рады, что вы сделали репост! Теперь вы участвуете в конкурсе на 100к VKC!</p>
  88.           </Alert>
  89.         });
  90.       };
  91.  
  92.       closePopout = () => {
  93.         this.setState({ popout: null });
  94.     };
  95.  
  96.     position = () => {
  97.         connect.send("VKWebAppGetGeodata", {});
  98.     };
  99.  
  100.     todark = () => {
  101.     document.body.setAttribute( 'scheme','client_dark' );
  102.     };
  103.  
  104.     flashgetinfo = () => {
  105.         connect.send("VKWebAppFlashGetInfo", {});
  106.     };
  107.  
  108.     tolight = () => {
  109.     document.body.setAttribute( 'scheme','client_light' );
  110.     };
  111.  
  112.     getphone = () => {
  113.         connect.send("VKWebAppGetPhoneNumber", {});
  114.     };
  115.  
  116.     getfriends = () => {
  117.         connect.send("VKWebAppGetFriends", {});
  118.     };
  119.  
  120.     getemail = () => {
  121.         connect.send("VKWebAppGetEmail", {});
  122.     };
  123.  
  124.     noheader = () => {
  125.         this.setState({ header: false })
  126.     };
  127.  
  128.     openPopout3 = () => {
  129.         this.setState({ popout:
  130.           <Alert
  131.             actions={[{
  132.               title: 'Ок',
  133.               autoclose: true,
  134.               style: 'destructive'
  135.             }]}
  136.             onClose={this.closePopout}
  137.           >
  138.             <h2>Успех!</h2>
  139.             <p>Удалось получить информацию о фонарике!</p>
  140.           </Alert>
  141.         })
  142.     };
  143.  
  144.     openPopout2 = () => {
  145.         this.setState({ popout:
  146.           <Alert
  147.             actions={[{
  148.               title: 'Ок',
  149.               autoclose: true,
  150.               style: 'destructive'
  151.             }]}
  152.             onClose={this.closePopout}
  153.           >
  154.             <h2>Успех!</h2>
  155.             <p>Удалось добавить приложение в сообщество!</p>
  156.           </Alert>
  157.         })
  158.     };
  159.  
  160.     render() {
  161.         return (
  162.             <View popout={this.state.popout} activePanel={this.state.activePanel} header={this.state.header}>
  163.                 <Home id="home" fetchedUser={this.state.fetchedUser} getfriends={this.getfriends} addtocomm={this.addtocomm} go={this.go} share={this.share} />
  164.                 <Persik id="persik" go={this.go} />
  165.                 <Game id="game" go={this.go} />
  166.                 <MapView id="view" fetchedUser={this.state.fetchedUser} go={this.go} state={this.state} />
  167.                 <VKCoin id="coin1" go={this.go} share={this.share} />
  168.                 <Usites id="usites" go={this.go} />
  169.                 <Settings id="settings" go={this.go} todark={this.todark} tolight={this.tolight} noheader={this.noheader} />
  170.                 <Flash id="flash" go={this.go} flashlevel0={this.flashlevel0} flashlevel1={this.flashlevel1} />
  171.             </View>
  172.         );
  173.     }
  174. };
  175.  
  176. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement