mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
* initial market - routing - store - load market data * move drawer/drawerSlider / count/star badge to components/ui * filter market categories * shopItem with gem / gold * show count of purchable items * show count of purchable itemsshow drawer with currently owned items + DrawerHeaderTabs-Component * show featured gear * show Gear - filter by class - sort by (type, price, stats) - sort market items * Component: ItemRows - shows only the max items in one row (depending on the available width) * Sell Dialog + Balance Component * generic buy-dialog / attributes grid with highlight * buyItem - hide already owned gear * filter: hide locked/pinned - lock items if not enough gold * API: Sell multiple items * show avatar in buy-equipment-dialog with changed gear * market banner * misc fixes * filter by text * pin/unpin gear store actions * Sell API: amount as query-parameter * Update user.js * fixes * fix sell api amount test * add back stroke/fill currentColor * use scss variables
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
import Store from 'client/libs/store';
|
|
import deepFreeze from 'client/libs/deepFreeze';
|
|
import content from 'common/script/content/index';
|
|
import * as constants from 'common/script/constants';
|
|
import { asyncResourceFactory } from 'client/libs/asyncResource';
|
|
import axios from 'axios';
|
|
|
|
import actions from './actions';
|
|
import getters from './getters';
|
|
|
|
const IS_TEST = process.env.NODE_ENV === 'test'; // eslint-disable-line no-process-env
|
|
|
|
// Load user auth parameters and determine if it's logged in
|
|
// before trying to load data
|
|
let isUserLoggedIn = false;
|
|
|
|
let AUTH_SETTINGS = localStorage.getItem('habit-mobile-settings');
|
|
|
|
if (AUTH_SETTINGS) {
|
|
AUTH_SETTINGS = JSON.parse(AUTH_SETTINGS);
|
|
axios.defaults.headers.common['x-api-user'] = AUTH_SETTINGS.auth.apiId;
|
|
axios.defaults.headers.common['x-api-key'] = AUTH_SETTINGS.auth.apiToken;
|
|
isUserLoggedIn = true;
|
|
}
|
|
|
|
// Export a function that generates the store and not the store directly
|
|
// so that we can regenerate it multiple times for testing, when not testing
|
|
// always export the same route
|
|
|
|
let existingStore;
|
|
export default function () {
|
|
if (!IS_TEST && existingStore) return existingStore;
|
|
|
|
existingStore = new Store({
|
|
actions,
|
|
getters,
|
|
state: {
|
|
title: 'Habitica',
|
|
isUserLoggedIn,
|
|
user: asyncResourceFactory(),
|
|
tasks: asyncResourceFactory(), // user tasks
|
|
party: {
|
|
quest: {},
|
|
members: asyncResourceFactory(),
|
|
},
|
|
shops: {
|
|
market: asyncResourceFactory(),
|
|
},
|
|
myGuilds: [],
|
|
editingGroup: {}, // TODO move to local state
|
|
// content data, frozen to prevent Vue from modifying it since it's static and never changes
|
|
// TODO apply freezing to the entire codebase (the server) and not only to the client side?
|
|
// NOTE this takes about 10-15ms on a fast computer
|
|
content: deepFreeze(content),
|
|
constants: deepFreeze(constants),
|
|
},
|
|
});
|
|
|
|
return existingStore;
|
|
}
|