<commit_before>import Vue from 'vue'
import Vuex from 'vuex'

import pick from 'lodash.pick'

import api from './api'
import socket from './socket'
import * as types from './types'
import storage from '../lib/storage'

// websocket handler
const socketPlugin = store => {
	socket.receive(message => {
		const packet = JSON.parse(message.data)
		if (typeof packet.topic === 'string' && packet.topic.length > 0) {
			store.commit(packet.topic, packet.payload)
		}
	})

	store.subscribe(mutation => {
		if (mutation.type.startsWith('skt')) {
			socket.send({ topic: mutation.type, payload: mutation.payload })
		}
	})
}

Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		movies: {
			/* [id: number] Movie */
		},
		total: 0,
		config: {},
		options: {
			query: '',
			filterByOptions: [
				{ value: 'title', label: 'Title' },
				{ value: 'genre', label: 'Genre' },
				{ value: 'year', label: 'Year' },
				{ value: 'country', label: 'Country' },
				{ value: 'director', label: 'Director' },
				{ value: 'actor', label: 'Actor' },
			],
			filterBy: storage.get('filterBy') || 'title',
			sortByOptions: [
				{ value: 'title', label: 'Title' },
				{ value: 'runtime', label: 'Runtime' },
				{ value: 'added', label: 'Added' },
				{ value: 'last_watched', label: 'Watched W' },
				{ value: 'count_watched', label: 'Watched C' },
				{ value: 'year', label: 'Year' },
				{ value: 'imdb_rating', label: 'Rating' },
			],
			sortBy: storage.get('sortBy') || 'added',
			sortOrderOptions: ['asc', 'desc'],
			sortOrder: storage.get('sortOrder') || 'desc',
			mode: 'regular',
			limit: 50,
			offset: 0,
		},
		itemsOrder: [],
		lines: [],
	},

	actions: {
		[types.FETCH_CONFIG]: ({ commit }) =>
			api.getConfig(config => {
				commit(types.RECEIVE_CONFIG, config)
			}),

		[types.FETCH_COVER]: ({ commit }) =>
			api.getCover(movies => {
				// console.log(`movies-${JSON.stringify(movies)}`) // eslint-disable-line
				commit(types.RECEIVE_MOVIES, movies)<commit_msg>Sort by Score<commit_after>import Vue from 'vue'
import Vuex from 'vuex'

import pick from 'lodash.pick'

import api from './api'
import socket from './socket'
import * as types from './types'
import storage from '../lib/storage'

// websocket handler
const socketPlugin = store => {
	socket.receive(message => {
		const packet = JSON.parse(message.data)
		if (typeof packet.topic === 'string' && packet.topic.length > 0) {
			store.commit(packet.topic, packet.payload)
		}
	})

	store.subscribe(mutation => {
		if (mutation.type.startsWith('skt')) {
			socket.send({ topic: mutation.type, payload: mutation.payload })
		}
	})
}

Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		movies: {
			/* [id: number] Movie */
		},
		total: 0,
		config: {},
		options: {
			query: '',
			filterByOptions: [
				{ value: 'title', label: 'Title' },
				{ value: 'genre', label: 'Genre' },
				{ value: 'year', label: 'Year' },
				{ value: 'country', label: 'Country' },
				{ value: 'director', label: 'Director' },
				{ value: 'actor', label: 'Actor' },
			],
			filterBy: storage.get('filterBy') || 'title',
			sortByOptions: [
				{ value: 'title', label: 'Title' },
				{ value: 'runtime', label: 'Runtime' },
				{ value: 'added', label: 'Added' },
				{ value: 'last_watched', label: 'Watched W' },
				{ value: 'count_watched', label: 'Watched C' },
				{ value: 'year', label: 'Year' },
				{ value: 'imdb_rating', label: 'Rating' },
				{ value: 'score', label: 'Score' },
			],
			sortBy: storage.get('sortBy') || 'added',
			sortOrderOptions: ['asc', 'desc'],
			sortOrder: storage.get('sortOrder') || 'desc',
			mode: 'regular',
			limit: 50,
			offset: 0,
		},
		itemsOrder: [],
		lines: [],
	},

	actions: {
		[types.FETCH_CONFIG]: ({ commit }) =>
			api.getConfig(config => {
				commit(types.RECEIVE_CONFIG, config)
			}),

		[types.FETCH_COVER]: ({ commit }) =>
			api.getCover(movies => {
				// console.log(`movies-${JSON.stringify(movies)}`) // eslint-disable-line
				commit(types.RECEIVE_MOVIES, movies)
{'fraction_non_alphanumeric': 0.19600997506234413, 'fraction_numerical': 0.0024937655860349127, 'mean_word_length': 3.393209200438116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4593256', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1401, 'n_words': 321}