Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading shows from local storage. #10779

Merged
merged 4 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions medusa/server/api/v2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ def data_system():
"""System information."""
section_data = {}

section_data['configLoaded'] = True # More uniform way of checking of the config has loaded in frontend.
section_data['memoryUsage'] = helpers.memory_usage(pretty=True)
section_data['schedulers'] = generate_schedulers()
section_data['showQueue'] = generate_show_queue()
Expand Down
1 change: 1 addition & 0 deletions tests/apiv2/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def memory_usage_mock(*args, **kwargs):
monkeypatch.setattr(helpers, 'memory_usage', memory_usage_mock)

section_data = {}
section_data['configLoaded'] = True
section_data['memoryUsage'] = memory_usage_mock()
section_data['schedulers'] = [{'key': scheduler[0], 'name': scheduler[1]} for scheduler in all_schedulers]
section_data['showQueue'] = []
Expand Down
2 changes: 1 addition & 1 deletion themes-default/slim/src/components/add-show-options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export default {
computed: {
...mapState({
showDefaults: state => state.config.general.showDefaults,
configLoaded: state => state.config.general.wikiUrl !== null,
configLoaded: state => state.config.system.configLoaded,
layout: state => state.config.layout,
namingForceFolders: state => state.config.general.namingForceFolders,
subtitlesEnabled: state => state.config.subtitles.enabled,
Expand Down
2 changes: 1 addition & 1 deletion themes-default/slim/src/components/config-general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ export default {
computed: {
...mapState({
general: state => state.config.general,
configLoaded: state => state.config.consts.statuses.length > 0,
configLoaded: state => state.config.system.configLoaded,
layout: state => state.config.layout,
statuses: state => state.config.consts.statuses,
indexers: state => state.config.indexers,
Expand Down
7 changes: 2 additions & 5 deletions themes-default/slim/src/components/config-post-processing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,9 @@ export default {
metadata: state => state.config.metadata,
postprocessing: state => state.config.postprocessing,
torrentMethod: state => state.config.clients.torrents.method,
system: state => state.config.system
system: state => state.config.system,
configLoaded: state => state.config.system.configLoaded
}),
configLoaded() {
const { postprocessing } = this;
return postprocessing.processAutomatically !== null;
},
multiEpStringsSelect() {
const { postprocessing } = this;
if (!postprocessing.multiEpStrings) {
Expand Down
1 change: 0 additions & 1 deletion themes-default/slim/src/components/config-search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ export default {
},
data() {
return {
configLoaded: false,
checkPropersIntervalLabels: [
{ text: '24 hours', value: 'daily' },
{ text: '4 hours', value: '4h' },
Expand Down
2 changes: 1 addition & 1 deletion themes-default/slim/src/components/display-show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ export default {
...mapState({
shows: state => state.shows.shows,
subtitles: state => state.config.subtitles,
configLoaded: state => state.config.layout.fanartBackground !== null,
configLoaded: state => state.config.system.configLoaded,
layout: state => state.config.layout,
stateSearch: state => state.config.search,
client: state => state.auth.client
Expand Down
24 changes: 19 additions & 5 deletions themes-default/slim/src/components/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export default {
config: state => state.config.general,
// Renamed because of the computed property 'layout'.
stateLayout: state => state.config.layout,
stats: state => state.stats
stats: state => state.stats,
configLoaded: state => state.config.system.configLoaded
}),
...mapGetters({
showsWithStats: 'showsWithStats',
Expand Down Expand Up @@ -146,7 +147,8 @@ export default {
setLayoutShow: 'setLayoutShow',
setStoreLayout: 'setStoreLayout',
setLayoutLocal: 'setLayoutLocal',
getStats: 'getStats'
getStats: 'getStats',
initShowsFromLocalStorage: 'initShowsFromLocalStorage'
}),
async changePosterSortBy() {
// Patch new posterSOrtBy value
Expand All @@ -172,10 +174,22 @@ export default {
},
mounted() {
const { getStats } = this;
const { initShowsFromLocalStorage } = this;

if (this.configLoaded) {
// Load straigt away.
initShowsFromLocalStorage();
} else {
// Wait for a state change.
const unwatchProp = this.$watch('configLoaded', configLoaded => {
if (configLoaded) {
initShowsFromLocalStorage();
unwatchProp();
}
});
}

getStats('show');
},
beforeCreate() {
this.$store.commit('initShowsFromStore');
}
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion themes-default/slim/src/components/irc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
name: 'irc',
computed: {
...mapState({
configLoaded: state => state.config.system.pythonVersion !== null,
configLoaded: state => state.config.system.configLoaded,
gitUsername: state => state.config.general.git.username
}),
frameSrc() {
Expand Down
1 change: 0 additions & 1 deletion themes-default/slim/src/components/recommended.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export default {
sortDirectionOptionsValue: 'desc',
filterOption: null,
filterShows: '',
configLoaded: false,
rootDirs: [],
enableShowOptions: false,
selectedShowOptions: {
Expand Down
2 changes: 1 addition & 1 deletion themes-default/slim/src/components/show-header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export default {
qualities: state => state.config.consts.qualities.values,
statuses: state => state.config.consts.statuses,
search: state => state.config.search,
configLoaded: state => state.config.layout.fanartBackground !== null,
configLoaded: state => state.config.system.configLoaded,
client: state => state.auth.client
}),
...mapGetters({
Expand Down
1 change: 1 addition & 0 deletions themes-default/slim/src/store/modules/config/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ADD_CONFIG, ADD_REMOTE_BRANCHES, ADD_SHOW_QUEUE_ITEM } from '../../muta
*/

const state = {
configLoaded: false,
branch: null,
memoryUsage: null,
schedulers: [],
Expand Down
9 changes: 7 additions & 2 deletions themes-default/slim/src/store/modules/shows.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@ const mutations = {
[REMOVE_SHOW](state, removedShow) {
state.shows = state.shows.filter(existingShow => removedShow.id.slug !== existingShow.id.slug);
},
initShowsFromStore(state) {
loadShowsFromStore(state, namespace) {
// Check if the ID exists
// Update (namespaced) localStorage
if (localStorage.getItem('shows')) {
Vue.set(state, 'shows', JSON.parse(localStorage.getItem('shows')));
Vue.set(state, 'shows', JSON.parse(localStorage.getItem(`${namespace}shows`)));
}
}
};
Expand Down Expand Up @@ -576,6 +577,10 @@ const actions = {
}
};
return rootState.auth.client.api.patch(`series/${show.indexer}${show.id[show.indexer]}`, data);
},
initShowsFromLocalStorage({ rootState, commit }) {
const namespace = rootState.config.system.webRoot ? `${rootState.config.system.webRoot}_` : '';
return commit('loadShowsFromStore', namespace);
}

};
Expand Down
1 change: 1 addition & 0 deletions themes-default/slim/test/__fixtures__/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@
}
},
"system": {
"configLoaded": true,
"memoryUsage": "56.85 MB",
"schedulers": [
{
Expand Down
22 changes: 11 additions & 11 deletions themes/dark/assets/js/medusa-runtime.js

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions themes/light/assets/js/medusa-runtime.js

Large diffs are not rendered by default.