import { render } from './iris/js/lib/preact.js'; import { Router, route } from './iris/js/lib/preact-router.es.js'; import { createHashHistory } from './iris/js/lib/history.production.min.js'; import { Component } from './iris/js/lib/preact.js'; import { Link } from './iris/js/lib/preact.match.js'; import Helpers from './iris/js/Helpers.js'; import { html } from './iris/js/Helpers.js'; import QRScanner from './iris/js/QRScanner.js'; import PeerManager from './iris/js/PeerManager.js'; import Session from './iris/js/Session.js'; import { translate as t } from './iris/js/Translation.js'; import Settings from './iris/js/views/Settings.js'; import LogoutConfirmation from './iris/js/views/LogoutConfirmation.js'; import Chat from './iris/js/views/Chat.js'; import Store from './iris/js/views/Store.js'; import Checkout from './iris/js/views/Checkout.js'; import Product from './iris/js/views/Product.js'; import Login from './iris/js/views/Login.js'; import Profile from './iris/js/views/Profile.js'; import Group from './iris/js/views/Group.js'; import Message from './iris/js/views/Message.js'; import Follows from './iris/js/views/Follows.js'; import Feed from './iris/js/views/Feed.js'; import About from './iris/js/views/About.js'; import Explorer from './iris/js/views/Explorer.js'; import Contacts from './iris/js/views/Contacts.js'; import Torrent from './iris/js/views/Torrent.js'; import VideoCall from './iris/js/components/VideoCall.js'; import Identicon from './iris/js/components/Identicon.js'; import MediaPlayer from './iris/js/components/MediaPlayer.js'; import Footer from './iris/js/components/Footer.js'; import State from './iris/js/State.js'; import Icons from './iris/js/Icons.js'; const userAgent = navigator.userAgent.toLowerCase(); const isElectron = (userAgent.indexOf(' electron/') > -1); if (!isElectron && ('serviceWorker' in navigator)) { window.addEventListener('load', function() { navigator.serviceWorker.register('iris/serviceworker.js') .catch(function(err) { // registration failed :( console.log('ServiceWorker registration failed: ', err); }); }); } State.init(); Session.init({autologin: true}); PeerManager.init(); Helpers.checkColorScheme(); const APPLICATIONS = [ // TODO: move editable shortcuts to State.local gun {url: '/', text: t('home'), icon: Icons.home}, {url: '/feed', text: t('feed'), icon: Icons.feed}, {url: '/media', text: t('media'), icon: Icons.play}, {url: '/settings', text: t('settings'), icon: Icons.settings}, {url: '/store', text: t('store'), icon: Icons.store}, {url: '/explorer', text: t('explorer'), icon: Icons.folder}, {url: '/chat', text: t('messages'), icon: Icons.chat}, // {url: '/store', text: t('store'), icon: Icons.store}, // restore when it works! {}, {url: '../stats.html', text: 'Gun node stats'}, {url: '../iris/index.html', text: 'Iris', icon: html``}, {url: '../infinite-scroll/index.html', text: 'Infinite scroll'}, {url: '../chat/index.html', text: 'Chat'}, {url: '../game/space.html', text: 'Space'}, {}, {url: 'https://gun.eco/docs/', text: 'Gun documentation'}, {url: 'https://examples.iris.to/components/', text: 'Iris web components'} ]; const HomeView = () => { return html`

Hello, world!

Here you can find sample applications and utilities for GUN.

If you need any help, please feel free to join the GUN community chat: http://chat.gun.eco

Explorer

Explore the data saved on the GUN database. Open to the side while using an application and see the data change in real-time.

Space

Spaceflight game. Open in 2 or more browser windows.

Iris

Decentralized Twitter/Instagram. Provides modular components that can be reused in other applications (including this one).

Chat

Shoutbox!

`; }; class MenuView extends Component { componentDidMount() { State.local.get('showMenu').on(showMenu => this.setState({showMenu})); } render() { const pub = Session.getPubKey(); return html`
<${Identicon} str=${pub} width=40/>

${APPLICATIONS.map(a => { if (a.url) { return html` ${a.icon || Icons.circle} ${a.text} `; } else { return html`

`; } })}
`; } }; class Main extends Component { constructor() { super(); this.showMenu = false; } componentDidMount() { State.local.get('loggedIn').on(loggedIn => this.setState({loggedIn})); } handleRoute(e) { let activeRoute = e.url; if (!activeRoute && window.location.hash) { return route(window.location.hash.replace('#', '')); // bubblegum fix back navigation } document.title = 'Iris'; if (activeRoute && activeRoute.length > 1) { document.title += ' - ' + Helpers.capitalize(activeRoute.replace('/', '')); } State.local.get('activeRoute').put(activeRoute); QRScanner.cleanupScanner(); } onClickOverlay() { if (this.state.showMenu) { this.setState({showMenu: false}); } } toggleMenu(show) { this.setState({showMenu: typeof show === 'undefined' ? !this.state.showMenu : show}); } render() { const content = this.state.loggedIn ? html`
State.local.get('showMenu').put(this.showMenu = !this.showMenu)} style="padding: 5px;cursor:pointer;" viewBox="0 -53 384 384" width="40px">
<${MenuView}/>
<${Router} history=${createHashHistory()} onChange=${e => this.handleRoute(e)}> <${HomeView} path="/"/> <${Feed} path="/feed"/> <${Feed} path="/search/:term?/:type?"/> <${Feed} path="/media" index="media"/> <${Login} path="/login"/> <${Chat} path="/chat/:id?"/> <${Message} path="/post/:hash"/> <${Torrent} path="/torrent/:id"/> <${About} path="/about"/> <${Settings} path="/settings"/> <${LogoutConfirmation} path="/logout"/> <${Profile} path="/profile/:id?" tab="profile"/> <${Profile} path="/replies/:id?" tab="replies"/> <${Profile} path="/likes/:id?" tab="likes"/> <${Profile} path="/media/:id" tab="media"/> <${Group} path="/group/:id?"/> <${Store} path="/store/:store?"/> <${Checkout} path="/checkout/:store?"/> <${Product} path="/product/:product/:store"/> <${Product} path="/product/new" store=Session.getPubKey()/> <${Explorer} path="/explorer/:node"/> <${Explorer} path="/explorer"/> <${Follows} path="/follows/:id"/> <${Follows} followers=${true} path="/followers/:id"/> <${Contacts} path="/contacts"/>
<${VideoCall}/> ` : ''; return html`
${content}
`; } } render(html`<${Main}/>`, document.body); $('body').css('opacity', 1); // use opacity because setting focus on display: none elements fails