Skip to content
Snippets Groups Projects
App.vue 9.79 KiB
Newer Older
  • Learn to ignore specific revisions
  •     <!-- here, we display custom stylesheets, if any -->
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        <link
          v-for="url in customStylesheets"
          rel="stylesheet"
          property="stylesheet"
          :href="url"
          :key="url"
        >
    
        <div class="ui main text container instance-chooser" v-if="!$store.state.instance.instanceUrl">
          <div class="ui padded segment">
    
    Eliot Berriot's avatar
    Eliot Berriot committed
            <h1 class="ui header">
              <translate>Choose your instance</translate>
            </h1>
    
            <form class="ui form" @submit.prevent="$store.dispatch('instance/setUrl', instanceUrl)">
    
    Eliot Berriot's avatar
    Eliot Berriot committed
              <p>
                <translate>You need to select an instance in order to continue</translate>
              </p>
    
              <div class="ui action input">
                <input type="text" v-model="instanceUrl">
    
    Eliot Berriot's avatar
    Eliot Berriot committed
                <button type="submit" class="ui button">
                  <translate>Submit</translate>
                </button>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
              <p>
                <translate>Suggested choices</translate>
              </p>
    
              <div class="ui bulleted list">
                <div class="ui item" v-for="url in suggestedInstances">
                  <a @click="instanceUrl = url">{{ url }}</a>
    
            </form>
          </div>
        </div>
        <template v-else>
          <sidebar></sidebar>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
          <service-messages v-if="messages.length > 0"/>
    
          <router-view :key="$route.fullPath"></router-view>
          <div class="ui fitted divider"></div>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
          <app-footer
            :version="version"
            @show:shortcuts-modal="showShortcutsModal = !showShortcutsModal"
          ></app-footer>
    
          <raven
            v-if="$store.state.instance.settings.raven.front_enabled.value"
    
    Eliot Berriot's avatar
    Eliot Berriot committed
            :dsn="$store.state.instance.settings.raven.front_dsn.value"
          ></raven>
    
          <playlist-modal v-if="$store.state.auth.authenticated"></playlist-modal>
    
          <shortcuts-modal @update:show="showShortcutsModal = $event" :show="showShortcutsModal"></shortcuts-modal>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
          <GlobalEvents @keydown.h.exact="showShortcutsModal = !showShortcutsModal"/>
    
    import axios from 'axios'
    import _ from 'lodash'
    
    import {mapState} from 'vuex'
    
    import { WebSocketBridge } from 'django-channels'
    
    import GlobalEvents from '@/components/utils/global-events'
    
    import translations from '@/translations'
    
    
    import Sidebar from '@/components/Sidebar'
    
    import Raven from '@/components/Raven'
    
    import ServiceMessages from '@/components/ServiceMessages'
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    import PlaylistModal from '@/components/playlists/PlaylistModal'
    
    import ShortcutsModal from '@/components/ShortcutsModal'
    
      components: {
        Sidebar,
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        Raven,
    
          bridge: null,
    
        this.openWebsocket()
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        let self = this
    
        setInterval(() => {
          // used to redraw ago dates every minute
          self.$store.commit('ui/computeLastDate')
        }, 1000 * 60)
    
        if (!this.$store.state.instance.instanceUrl) {
          let defaultInstanceUrl = process.env.VUE_APP_INSTANCE_URL || this.$store.getters['instance/defaultUrl']()
          this.$store.commit('instance/instanceUrl', defaultInstanceUrl)
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        } else {
          // needed to trigger initialization of axios
          this.$store.commit('instance/instanceUrl', this.$store.state.instance.instanceUrl)
    
        this.$store.dispatch('auth/check')
        this.$store.dispatch('instance/fetchSettings')
        this.fetchNodeInfo()
    
        this.$store.commit('ui/addWebsocketEventHandler', {
          eventName: 'inbox.item_added',
          id: 'sidebarCount',
          handler: this.incrementNotificationCountInSidebar
        })
      },
      destroyed () {
        this.$store.commit('ui/removeWebsocketEventHandler', {
          eventName: 'inbox.item_added',
          id: 'sidebarCount',
        })
        this.disconnect()
    
        incrementNotificationCountInSidebar (event) {
          this.$store.commit('ui/incrementNotifications', {type: 'inbox', count: 1})
        },
    
        fetchNodeInfo () {
          let self = this
          axios.get('instance/nodeinfo/2.0/').then(response => {
            self.nodeinfo = response.data
          })
    
          let confirm = window.confirm(this.$gettext('This will erase your local data and disconnect you, do you want to continue?'))
    
          if (confirm) {
            this.$store.commit('instance/instanceUrl', null)
          }
    
        },
        autodetectLanguage () {
          let userLanguage = navigator.language || navigator.userLanguage
          let available = _.keys(translations)
          let matching = available.filter((a) => {
            return userLanguage.replace('-', '_') === a
          })
          let almostMatching = available.filter((a) => {
            return userLanguage.replace('-', '_').split('_')[0] === a.split('_')[0]
          })
          if (matching.length > 0) {
            this.$language.current = matching[0]
          } else if (almostMatching.length > 0) {
            this.$language.current = almostMatching[0]
          }
    
        },
        disconnect () {
          if (!this.bridge) {
            return
          }
          this.bridge.socket.close(1000, 'goodbye', {keepClosed: true})
        },
        openWebsocket () {
          if (!this.$store.state.auth.authenticated) {
            return
          }
          this.disconnect()
          let self = this
          let token = this.$store.state.auth.token
          // let token = 'test'
          const bridge = new WebSocketBridge()
          this.bridge = bridge
          let url = this.$store.getters['instance/absoluteUrl'](`api/v1/activity?token=${token}`)
          url = url.replace('http://', 'ws://')
          url = url.replace('https://', 'wss://')
          bridge.connect(
            url,
            null,
            {reconnectInterval: 5000})
          bridge.listen(function (event) {
            self.$store.dispatch('ui/websocketEvent', event)
          })
          bridge.socket.addEventListener('open', function () {
            console.log('Connected to WebSocket')
          })
    
        ...mapState({
          messages: state => state.ui.messages
        }),
    
          let instances = [this.$store.getters['instance/defaultUrl'](), 'https://demo.funkwhale.audio']
    
        version () {
          if (!this.nodeinfo) {
            return null
          }
          return _.get(this.nodeinfo, 'software.version')
    
        },
        customStylesheets () {
          if (this.$store.state.instance.frontSettings) {
            return this.$store.state.instance.frontSettings.additionalStylesheets || []
          }
    
      },
      watch: {
        '$store.state.instance.instanceUrl' () {
          this.$store.dispatch('instance/fetchSettings')
          this.fetchNodeInfo()
    
        '$store.state.auth.authenticated' (newValue) {
          if (!newValue) {
            this.disconnect()
          } else {
            this.openWebsocket()
          }
        },
    
        '$language.current' (newValue) {
          this.$store.commit('ui/currentLanguage', newValue)
    
    }
    </script>
    
    <style lang="scss">
    // we do the import here instead in main.js
    // as resolve order is not deterministric in webpack
    // and we end up with CSS rules not applied,
    // see https://github.com/webpack/webpack/issues/215
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    @import "semantic/semantic.css";
    @import "style/vendor/media";
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    html,
    body {
    
      @include media("<desktop") {
    
        font-size: 90%;
    
    Eliot Berriot's avatar
    Eliot Berriot committed
      font-family: "Avenir", Helvetica, Arial, sans-serif;
    
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    .main.pusher,
    .footer {
    
      @include media(">desktop") {
        margin-left: 350px !important;
    
        margin-top: 50px;
    
    
    .main.pusher > .ui.secondary.menu {
      margin-left: 0;
      margin-right: 0;
      border: none;
      box-shadow: inset 0px -2px 0px 0px rgba(34, 36, 38, 0.15);
      .ui.item {
        border: none;
        border-bottom-style: none;
        margin-bottom: 0px;
        &.active {
          box-shadow: inset 0px -2px 0px 0px #000;
        }
      }
      @include media(">tablet") {
        padding: 0 2.5rem;
      }
      @include media(">desktop") {
        position: fixed;
        left: 350px;
        right: 0px;
        top: 0px;
    
      }
      background-color: white;
      .item {
        padding-top: 1.5em;
        padding-bottom: 1.5em;
      }
    }
    
    
    .service-messages {
      position: fixed;
      bottom: 1em;
      left: 1em;
      @include media(">desktop") {
        left: 350px;
      }
    }
    
    .main-pusher {
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    .ui.stripe.segment,
    #footer {
    
      padding: 2em;
      @include media(">tablet") {
        padding: 4em;
      }
    
    .ellipsis {
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
    
    
    .ui.small.text.container {
      max-width: 500px !important;
    }
    
    .button.icon.tiny {
    
    Eliot Berriot's avatar
    Eliot Berriot committed
      padding: 0.5em !important;
    
    .discrete {
      color: rgba(0, 0, 0, 0.87);
    }
    .link {
      cursor: pointer;
    
    .ui.really.basic.button {
      &:not(:focus) {
        box-shadow: none !important;
        background-color: none !important;
      }
    }
    
    
    .floated.buttons .button ~ .dropdown {
      border-left: none;
    }
    
    
    .ui.icon.header .circular.icon {
      display: flex;
      justify-content: center;
    }
    
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    .segment-content .button {
      margin: 0.5em;
    
    .segment.hidden {
      display: none;
    }
    
    button.reset {
      border: none;
      margin: 0;
      padding: 0;
      width: auto;
      overflow: visible;
    
      background: transparent;
    
      /* inherit font & color from ancestor */
      color: inherit;
      font: inherit;
    
      /* Normalize `line-height`. Cannot be changed from `normal` in Firefox 4+. */
      line-height: normal;
    
      /* Corrects font smoothing for webkit */
      -webkit-font-smoothing: inherit;
      -moz-osx-font-smoothing: inherit;
    
    Eliot Berriot's avatar
    Eliot Berriot committed
      /* Corrects inability to style clickable `input` types in iOS */
    
    
    .ui.table > caption {
      font-weight: bold;
      padding: 0.5em;
      text-align: left;
    }
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    [role="button"] {
      cursor: pointer;
    }
    
    
    .left.floated {
      float: left;
    }
    
    .right.floated {
      float: right;
    }