Plugins - AmericanWhitewater/wh2o-vue GitHub Wiki

Plugins

@/app/plugins/

Here are the projects in house and third-party plugins. "Plugins" is used loosely. The project information hierarchy/file organization needs to be revisited.

Vue Apollo

@/app/plugins/vue-apollo/

At the time of this writing, we have still not been able to wire upload functionality with the API. If we can solve this problem without using vue-apollo then we can remove it. Vuex handles state management.

Apollo Dev Helper

This is a separate Vue instance to serve as a GQL dev helper. Once mounted, it creates a connection with the beta GQL server and enables the Apollo Chrome extension explorer. The extension's Explorer shows you all the available query fields and mutations on the beta GQL server. Use this as a way to test and fine-tune queries/mutations.

Vuex is still our preferred approach for state management at this time.

Usage

To enable, place any truthy value in the VUE_APP_APOLLO_DEV_HELPER= .env variable.

Tooling

NPM Packages

Exception Handler

@/app/plugins/exception-handler.js

This is a simple exception handler which provides more Vue specific info. It is essential only to use this during development to avoid conflict with Sentry.

if (environment === 'development') {
  Vue.config.errorHandler = (err, vm, info) => {
    logger.logToServer({ err, vm, info })
  }

  window.onerror = function (message, source, lineno, colno, error) {
    logger.logToServer({
      message,
      source,
      lineno,
      colno,
      error
    })
  }
}

Network Status

@/app/plugins/network-status.js

Used to update the UI when the user's network connection is lost. Visit the Offline section for more info about Progressive Web Apps.

if (!navigator.onLine) {
  store.dispatch(globalAppActions.NETWORK_STATUS, 'offline')
} else {
  store.dispatch(globalAppActions.NETWORK_STATUS, 'online')
}

window.addEventListener('offline', function (e) {
  store.dispatch(globalAppActions.NETWORK_STATUS, 'offline')
})

window.addEventListener('online', function (e) {
  store.dispatch(globalAppActions.NETWORK_STATUS, 'online')
})

Random ID

@/app/plugins/random-id.js

Used to generate unique IDs for newly created resources.

Vue.prototype.$randomId = nanoid(
  21,
  '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
)

NPM Packages

Sentry

@/app/plugins/sentry.js

Error monitoring / logging for production environments with Sentry.io.

NPM Packages

Vue Check View

@/app/plugins/vue-check-view.js

A custom Vue Directive used to load below the fold content like rapids and comments dynamically. It checks to see if the element is in the viewport then trigger an API call.

//
@/app/views/river-detail/main-tab/components/rapids-section/rapids-section.vue

<section v-view.once="loadRapids"> ... </section>

NPM Packages

Vue Gtag

@/app/plugins/vue-gtag.js

This package installs and configures Google analytics.

NPM Packages

Vue Sanitize

@/app/plugins/vue-sanitize.js

Use vue-sanitize for cleaning up HTML markup in river descriptions, news articles, and other user-generated content. The old rich text editor was very loose with what users could do. To keep page content styling consistent, we use vue-sanitize to remove inline CSS styles and replace headline tags that do not fit within our typographic hierarchy.

NPM Packages

Vue Social Sharing

@/app/plugins/vue-social-sharing.js

Used for handling all social media sharing functionality. Currently only used in news articles.

NPM Packages

⚠️ **GitHub.com Fallback** ⚠️