Files
habitica/website/client/store/getters/tasks.js
T
Keith Holliday 356f2c7b7f Sept 26 fixes (#9081)
* Fixed layering of avatar

* Fixed navbar padding on small screens

* Dropdowns go left

* Adjusted member details styles

* Fixed task tag display

* Added toggle to buy gems

* Began moving presskit

* Fixed easing and validating immediately

* Added hover state to login and fixed transitions for social buttons

* Fixed more style issues

* Fixed overflow

* Added email warning

* Show login button on mobile

* Some column adjustments for mobile

* Fixed email/username confusion
2017-09-26 15:04:29 -05:00

73 lines
2.2 KiB
JavaScript

import { shouldDo } from 'common/script/cron';
// Return all the tags belonging to an user task
export function getTagsFor (store) {
return (task) => {
return store.state.user.data.tags
.filter(tag => task.tags && task.tags.indexOf(tag.id) !== -1)
.map(tag => tag.name);
};
}
function getTaskColorByValue (value) {
if (value < -20) {
return 'task-worst';
} else if (value < -10) {
return 'task-worse';
} else if (value < -1) {
return 'task-bad';
} else if (value < 1) {
return 'task-neutral';
} else if (value < 5) {
return 'task-good';
} else if (value < 10) {
return 'task-better';
} else {
return 'task-best';
}
}
export function getTaskClasses (store) {
const userPreferences = store.state.user.data.preferences;
// Purpose is one of 'controls', 'editModal', 'createModal', 'content'
return (task, purpose, dueDate) => {
if (!dueDate) dueDate = new Date();
const type = task.type;
switch (purpose) {
case 'createModal':
return 'task-purple';
case 'editModal':
return type === 'reward' ? 'task-purple' : getTaskColorByValue(task.value);
case 'controlCreate':
return {
up: task.up ? 'task-purple' : 'task-habit-disabled',
down: task.down ? 'task-purple' : 'task-habit-disabled',
};
case 'control':
switch (type) {
case 'daily':
if (task.completed || !shouldDo(dueDate, task, userPreferences)) return 'task-daily-todo-disabled';
return getTaskColorByValue(task.value);
case 'todo':
if (task.completed) return 'task-daily-todo-disabled';
return getTaskColorByValue(task.value);
case 'habit':
return {
up: task.up ? getTaskColorByValue(task.value) : 'task-habit-disabled',
down: task.down ? getTaskColorByValue(task.value) : 'task-habit-disabled',
};
case 'reward':
return 'task-reward';
}
break;
case 'content':
if (type === 'daily' && (task.completed || !shouldDo(dueDate, task, userPreferences)) || type === 'todo' && task.completed) {
return 'task-daily-todo-content-disabled';
}
break;
}
};
}