Skip to content

Commit

Permalink
Revert back to global defaults, clean up stores and rename config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
defkev authored and johman10 committed Nov 16, 2023
1 parent fd93fb3 commit edb6e11
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/public/build/
/public/sw.js*
/public/workbox-*.js*
/public/config.json

.DS_Store

Expand Down
File renamed without changes.
34 changes: 31 additions & 3 deletions src/helpers/configHelper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
// DEFAULT configuration, can be (selectively) overwritten in /flood-for-transmission/public/config.json
// Check /flood-for-transmission/public/config.json.defaults to get started
const defaults = {
DARK_MODE: 'auto', // String (enabled, disabled, auto)
SWITCH_COLORS: false, // Boolean
NOTATION_24H: true, // Boolean
WRAP_HEADER: false, // Boolean
COMMON_PATH: [], // Array of Strings
COLUMNS: [ // Array of Strings in the order they should appear
'Name',
'Progress',
'ETA',
'Download Speed',
'Upload Speed',
'File Size',
'Downloaded',
'Uploaded',
'Downloading from',
'Seeding to'
],
SORT_COLUMN: 'Progress', // String
SORT_DIRECTION: 'desc' // String (asc, desc)
};

export default await fetch('./config.json')
.then((res) => {
return res.json();
if (res.ok) {
return res.json();
} else {
console.info('No config.json found, using default values:\nSee https://github.com/johman10/flood-for-transmission#beta-customization');
}
})
.then((config) => {
return config;
return {...defaults, ...config};
})
.catch((e) => {
console.error('Something went wrong while fetching config.json', e);
return {};
return defaults;
});
27 changes: 0 additions & 27 deletions src/helpers/constants/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,137 +317,110 @@ export const UI_COLUMN = {
export const DEFAULT_COLUMNS = [
{
id: UI_COLUMN.NAME.id,
enabled: true,
width: 600,
},
{
id: UI_COLUMN.PROGRESS_BAR.id,
enabled: true,
width: 300,
},
{
id: UI_COLUMN.ETA.id,
enabled: true,
width: 100,
},
{
id: UI_COLUMN.DOWNLOAD_SPEED.id,
enabled: true,
width: 100,
},
{
id: UI_COLUMN.UPLOAD_SPEED.id,
enabled: true,
width: 100,
},
{
id: UI_COLUMN.FILE_SIZE.id,
enabled: true,
width: 100,
},
{
id: UI_COLUMN.DOWNLOADED.id,
enabled: true,
width: 100,
},
{
id: UI_COLUMN.UPLOADED.id,
enabled: true,
width: 100,
},
{
id: UI_COLUMN.PEERS.id,
enabled: true,
width: 100,
},
{
id: UI_COLUMN.SEEDS.id,
enabled: true,
width: 100,
},
{
id: UI_COLUMN.ADDED.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.BASE_PATH.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.COMMENT.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.CREATION_DATE.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.HASH.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.PRIVATE.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.LABELS.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.ERROR.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.TRACKERS.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.RATIO.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.DONE.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.STATUS.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.QUEUE_POSITION.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.TOTAL_LEECHERS.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.TOTAL_SEEDERS.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.ACTIVITY.id,
enabled: false,
width: 100,
},
{
id: UI_COLUMN.PERCENT_COMPLETE.id,
enabled: false,
width: 100,
},
];
Expand Down
26 changes: 12 additions & 14 deletions src/helpers/stores/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ const UI_COLUMNS_STORAGE_KEY = 'ui-columns';
const UI_COLUMN_VALUES = Object.values(UI_COLUMN);
const UI_COLUMN_IDS = UI_COLUMN_VALUES.map((column) => column.id);

if (config.COLUMNS) {
DEFAULT_COLUMNS.map((dcolumn) => {
UI_COLUMN_VALUES.map((column) => {
if (dcolumn.id === column.id) {
dcolumn.enabled = config.COLUMNS.includes(column.label)
if (dcolumn.enabled) {
let fromIndex = DEFAULT_COLUMNS.indexOf(dcolumn)
let toIndex = config.COLUMNS.indexOf(column.label)
DEFAULT_COLUMNS.splice(fromIndex, 1)
DEFAULT_COLUMNS.splice(toIndex, 0, dcolumn)
}
DEFAULT_COLUMNS.map((dcolumn) => {
UI_COLUMN_VALUES.map((column) => {
if (dcolumn.id === column.id) {
dcolumn.enabled = config.COLUMNS.includes(column.label);
if (dcolumn.enabled) {
let fromIndex = DEFAULT_COLUMNS.indexOf(dcolumn);
let toIndex = config.COLUMNS.indexOf(column.label);
DEFAULT_COLUMNS.splice(fromIndex, 1);
DEFAULT_COLUMNS.splice(toIndex, 0, dcolumn);
}
})
})
}
}
});
});

function storeColumns(columns) {
const columnIds = Object.keys(COLUMN_MAP).map((column) =>
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/stores/darkMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const browserPrefersDarkModeStore = readable(

// Returns the value from the storage or 'auto' if no storage value is found
function getConfiguredValue() {
return window.localStorage.getItem(LOCAL_STORAGE_KEY) ?? config.DARK_MODE ?? 'auto';
return window.localStorage.getItem(LOCAL_STORAGE_KEY) ?? config.DARK_MODE;
}

// Returns whether darkMode is enabled
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/stores/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { writable } from 'svelte/store';
const PATHS_STORAGE_KEY = 'paths';

function getPaths() {
const storedPaths = window.localStorage.getItem(PATHS_STORAGE_KEY);
if (storedPaths) return JSON.parse(storedPaths);
return config.COMMON_PATH ?? []
return JSON.parse(window.localStorage.getItem(PATHS_STORAGE_KEY)) ?? config.COMMON_PATH;
}

function cleanValue(value) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/stores/sorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { uiColumns } from '~helpers/stores';

const SORTING_STORAGE_KEY = 'torrent-sorting';
const DEFAULT_SORTING = {
id: (Object.values(UI_COLUMN).find(column => column.label === config.SORT_COLUMN) ?? UI_COLUMN_PROGRESS_BAR).id,
direction: config.SORT_DIRECTION ?? 'desc',
id: Object.values(UI_COLUMN).find(column => column.label === config.SORT_COLUMN).id,
direction: config.SORT_DIRECTION
};

function storeSorting(value) {
Expand Down
6 changes: 1 addition & 5 deletions src/helpers/stores/switchSpeedColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { writable } from 'svelte/store';
const LOCAL_STORAGE_KEY = 'switchSpeedColors';

function getConfiguredValue() {
const storedConfig = window.localStorage.getItem(LOCAL_STORAGE_KEY);
if (storedConfig === null) {
return config.SWITCH_COLORS ?? false;
}
return storedConfig === 'true';
return JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY)) ?? config.SWITCH_COLORS;
}

function createSwitchSpeedColors() {
Expand Down
6 changes: 1 addition & 5 deletions src/helpers/stores/tableHeaderConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { writable } from 'svelte/store';
const LOCAL_STORAGE_KEY = 'tableHeaderConfig';

function getConfiguredValue() {
const storedConfig = window.localStorage.getItem(LOCAL_STORAGE_KEY);
if (storedConfig === null) {
return config.WRAP_HEADER ?? false;
}
return storedConfig === 'true';
return JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY)) ?? config.WRAP_HEADER;
}

function createTableHeaderConfig() {
Expand Down
6 changes: 1 addition & 5 deletions src/helpers/stores/timeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { writable } from 'svelte/store';
const LOCAL_STORAGE_KEY = 'timeConfig';

function getConfiguredValue() {
const storedConfig = window.localStorage.getItem(LOCAL_STORAGE_KEY);
if (storedConfig === null) {
return config.NOTATION_24H ?? true;
}
return storedConfig === 'true';
return JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY)) ?? config.NOTATION_24H;
}

function createTimeConfig() {
Expand Down

0 comments on commit edb6e11

Please sign in to comment.