moving tasks to independent app objects

This commit is contained in:
sairaj mote 2024-02-20 02:23:50 +05:30
parent fb029fea3d
commit 7861243e81
6 changed files with 70 additions and 43 deletions

View File

@ -963,7 +963,7 @@ ol {
padding: 3rem 0; padding: 3rem 0;
} }
#category_selection ul { #category_selection ul {
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
} }
#emblem { #emblem {
display: none; display: none;

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -1037,7 +1037,7 @@ ol {
#category_selection { #category_selection {
ul { ul {
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
} }
} }

View File

@ -5,6 +5,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RanchiMall Selects</title> <title>RanchiMall Selects</title>
<meta name="description" content="RanchiMall's ">
<link rel="stylesheet" href="css/main.min.css"> <link rel="stylesheet" href="css/main.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
@ -48,14 +49,14 @@
<div class="flex-column flex-1 gap-0-3"> <div class="flex-column flex-1 gap-0-3">
<label class="label" for="task_popup__category">Category*</label> <label class="label" for="task_popup__category">Category*</label>
<sm-chips name="category" id="task_popup__category" class="flex-1" multiline> <sm-chips name="category" id="task_popup__category" class="flex-1" multiline>
<sm-chip value="c00" selected>Creative Writing</sm-chip> <sm-chip value="jwrgfk" selected>Creative Writing</sm-chip>
<sm-chip value="c01">Marketing</sm-chip> <sm-chip value="u33rsr">Marketing</sm-chip>
<sm-chip value="c02">Design</sm-chip> <sm-chip value="n2b2a4">Design</sm-chip>
<sm-chip value="c03">Development</sm-chip> <sm-chip value="h5ml0g">Development</sm-chip>
<sm-chip value="c04">Social Media Management</sm-chip> <sm-chip value="mnmxqm">Social Media Management</sm-chip>
<sm-chip value="c05">Video Making</sm-chip> <sm-chip value="sgs6bv">Video Making</sm-chip>
<sm-chip value="c06">Project Scouting & Capital Raising</sm-chip> <sm-chip value="utpdbp">Project Scouting &amp; Capital Raising</sm-chip>
<sm-chip value="c07">Investment & Finance</sm-chip> <sm-chip value="hohq2a">Investment &amp; Finance</sm-chip>
</sm-chips> </sm-chips>
</div> </div>
<div class="flex-column flex-1"> <div class="flex-column flex-1">
@ -98,7 +99,7 @@
<script src="scripts/compactIDB.min.js" type="text/javascript"></script> <script src="scripts/compactIDB.min.js" type="text/javascript"></script>
<script src="scripts/floCloudAPI.min.js" type="text/javascript"></script> <script src="scripts/floCloudAPI.min.js" type="text/javascript"></script>
<script src="scripts/floDapps.min.js" type="text/javascript"></script> <script src="scripts/floDapps.min.js" type="text/javascript"></script>
<script src="scripts/app.min.js"></script> <script src="scripts/app.js"></script>
</body> </body>
</html> </html>

View File

@ -141,6 +141,12 @@ window.addEventListener('popstate', e => {
} }
}) })
//Function for displaying toast notifications. pass in error for mode param if you want to show an error. //Function for displaying toast notifications. pass in error for mode param if you want to show an error.
/**
* @param {string} message - Message to be displayed in the notification
* @param {string} mode - Mode of the notification. Can be 'success' or 'error' or ''
* @param {object} options - Options for the notification
* @param {boolean} options.pinned - If true, notification will not be dismissed automatically
*/
function notify(message, mode, options = {}) { function notify(message, mode, options = {}) {
let icon let icon
switch (mode) { switch (mode) {
@ -149,7 +155,8 @@ function notify(message, mode, options = {}) {
break; break;
case 'error': case 'error':
icon = `<svg class="icon icon--error" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-7v2h2v-2h-2zm0-8v6h2V7h-2z"/></svg>` icon = `<svg class="icon icon--error" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-7v2h2v-2h-2zm0-8v6h2V7h-2z"/></svg>`
options.pinned = true if (!options.hasOwnProperty('timeout'))
options.pinned = true
break; break;
} }
if (mode === 'error') { if (mode === 'error') {
@ -649,8 +656,6 @@ async function applyToTask(id) {
} }
function editTask(id) { function editTask(id) {
const task = floGlobals.appObjects.rmInterns.tasks.find(task => task.id === id);
if (!task) return notify('Task not found', 'error')
const { title, description, category, deadline } = task; const { title, description, category, deadline } = task;
getRef('task_popup__title_input').value = title; getRef('task_popup__title_input').value = title;
getRef('task_popup__description').value = description; getRef('task_popup__description').value = description;
@ -666,10 +671,10 @@ async function saveTask() {
}) })
if (!confirmation) return; if (!confirmation) return;
// save task // save task
const id = getRef('task_popup').dataset.taskId || Math.random().toString(36).substr(2, 9);
const title = getRef('task_popup__title_input').value; const title = getRef('task_popup__title_input').value;
const description = getRef('task_popup__description').value; const description = getRef('task_popup__description').value;
const category = getRef('task_popup__category').value; const category = getRef('task_popup__category').value;
const id = getRef('task_popup').dataset.taskId || category + '_' + Math.random().toString(36).substring(2, 9);
const deadline = getRef('task_popup__deadline').value; const deadline = getRef('task_popup__deadline').value;
const task = { const task = {
id, id,
@ -679,7 +684,7 @@ async function saveTask() {
deadline, deadline,
status: 'open' status: 'open'
} }
const foundTask = floGlobals.appObjects.rmInterns.tasks.find(task => task.id === id); const foundTask = floGlobals.appObjects[category].tasks.find(task => task.id === id);
if (foundTask) { if (foundTask) {
let taskDetailsChanged = false; let taskDetailsChanged = false;
// edit task only if something has changed // edit task only if something has changed
@ -693,10 +698,10 @@ async function saveTask() {
return notify('Please update at least one detail to save the changes', 'error') return notify('Please update at least one detail to save the changes', 'error')
} else { } else {
task.date = Date.now(); task.date = Date.now();
floGlobals.appObjects.rmInterns.tasks.unshift(task) floGlobals.appObjects[category].tasks.unshift(task);
} }
buttonLoader('task_popup__submit', true) buttonLoader('task_popup__submit', true)
floCloudAPI.updateObjectData('rmInterns') floCloudAPI.updateObjectData(category)
.then(response => { .then(response => {
notify('Task saved successfully', 'success') notify('Task saved successfully', 'success')
render.availableTasks(); render.availableTasks();
@ -716,18 +721,19 @@ async function deleteTask(id) {
danger: true danger: true
}) })
if (!confirmation) return; if (!confirmation) return;
const taskIndex = floGlobals.appObjects.rmInterns.tasks.findIndex(task => task.id === id); const [category] = id.split('_');
const taskIndex = floGlobals.appObjects[category].tasks.findIndex(task => task.id === id);
if (taskIndex < 0) return notify('Task not found', 'error'); if (taskIndex < 0) return notify('Task not found', 'error');
// in case of error, add the task back to the list // in case of error, add the task back to the list
const [cloneOfTaskToBeDeleted] = floGlobals.appObjects.rmInterns.tasks.splice(taskIndex, 1); const [cloneOfTaskToBeDeleted] = floGlobals.appObjects[category].tasks.splice(taskIndex, 1);
floCloudAPI.updateObjectData('rmInterns') floCloudAPI.updateObjectData(category)
.then(response => { .then(response => {
notify('Task deleted successfully', 'success') notify('Task deleted successfully', 'success')
}) })
.catch(e => { .catch(e => {
notify('An error occurred while deleting the task', 'error'); notify('An error occurred while deleting the task', 'error');
// add the task back to the list // add the task back to the list
floGlobals.appObjects.rmInterns.tasks.splice(taskIndex, 0, cloneOfTaskToBeDeleted); floGlobals.appObjects[category].tasks.splice(taskIndex, 0, cloneOfTaskToBeDeleted);
}).finally(() => { }).finally(() => {
closePopup() closePopup()
render.availableTasks(); render.availableTasks();
@ -770,18 +776,21 @@ const render = {
` `
}, },
availableTasks(options = {}) { availableTasks(options = {}) {
const { type } = options const { type } = options;
if ((floGlobals.appObjects?.rmInterns.tasks || []).length === 0) let availableTasks = [];
[...floGlobals.interestedCategories || Object.keys(floGlobals.taskCategories)].forEach(category => {
availableTasks.push(...floGlobals.appObjects[category].tasks)
})
if (availableTasks.length === 0)
return renderElem(getRef('available_tasks_list'), html`<p>No tasks available</p>`); return renderElem(getRef('available_tasks_list'), html`<p>No tasks available</p>`);
let tasksList = floGlobals.appObjects.rmInterns.tasks;
if (type) { if (type) {
if (type === 'applications') if (type === 'applications')
tasksList = tasksList.filter(task => floGlobals.applications.has(task.id)) availableTasks = availableTasks.filter(task => floGlobals.applications.has(task.id))
else if (type === 'available') else if (type === 'available')
tasksList = tasksList.filter(task => !floGlobals.applications.has(task.id)) availableTasks = availableTasks.filter(task => !floGlobals.applications.has(task.id))
} }
tasksList = tasksList.map(render.task); availableTasks = availableTasks.map(render.task);
renderElem(getRef('available_tasks_list'), html`${tasksList}`) renderElem(getRef('available_tasks_list'), html`${availableTasks}`)
} }
} }
@ -918,6 +927,10 @@ function toggleCategory(e, category) {
} }
function saveCategories() { function saveCategories() {
if (floGlobals.interestedCategories.size === 0)
return notify('Please select at least one category', 'error', {
timeout: 5000
})
localStorage.setItem('interestedCategories', JSON.stringify([...floGlobals.interestedCategories])); localStorage.setItem('interestedCategories', JSON.stringify([...floGlobals.interestedCategories]));
router.routeTo('landing'); router.routeTo('landing');
} }
@ -1093,7 +1106,12 @@ router.addRoute('profile', (state) => {
const { } = state; const { } = state;
let name = email = college = course = whatsappNumber = ''; let name = email = college = course = whatsappNumber = '';
if (floGlobals.userProfile) { if (floGlobals.userProfile) {
({ name, email, college, course, whatsappNumber }) = JSON.parse(floDapps.user.decipher(floGlobals.userProfile)); const userDetails = JSON.parse(floDapps.user.decipher(floGlobals.userProfile));
name = userDetails.name;
email = userDetails.email;
college = userDetails.college;
course = userDetails.course;
whatsappNumber = userDetails.whatsappNumber;
} }
renderElem(getRef('app_body'), html` renderElem(getRef('app_body'), html`
<article id="profile"> <article id="profile">
@ -1229,11 +1247,7 @@ window.addEventListener("load", () => {
}); });
floDapps.setMidStartup(() => floDapps.setMidStartup(() =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
Promise.all([ floCloudAPI.requestObjectData('rmInterns')
floCloudAPI.requestObjectData('rmInterns'),
floCloudAPI.requestObjectData('c00'),
floCloudAPI.requestObjectData('c01'),
])
.then(() => { .then(() => {
if (['#/landing', '#/sign_in', '#/sign_up'].some(route => window.location.hash.includes(route))) { if (['#/landing', '#/sign_in', '#/sign_up'].some(route => window.location.hash.includes(route))) {
router.routeTo(window.location.hash); router.routeTo(window.location.hash);
@ -1263,6 +1277,7 @@ window.addEventListener("load", () => {
try { try {
if (floGlobals.isSubAdmin) { if (floGlobals.isSubAdmin) {
const promises = [] const promises = []
await Promise.all(Object.keys(floGlobals.taskCategories).map(category => floCloudAPI.requestObjectData(category)))
for (const category in floGlobals.taskCategories) { for (const category in floGlobals.taskCategories) {
if (!floGlobals.appObjects[category]) { if (!floGlobals.appObjects[category]) {
console.log('resetting', category) console.log('resetting', category)
@ -1276,12 +1291,18 @@ window.addEventListener("load", () => {
await Promise.all(promises) await Promise.all(promises)
const taskApplications = floDapps.getNextGeneralData('taskApplications', '0'); const taskApplications = floDapps.getNextGeneralData('taskApplications', '0');
floGlobals.applications = {} floGlobals.applications = {}
floGlobals.allAvailableTasks = new Set();
for (const category in floGlobals.taskCategories) {
const tasks = floGlobals.appObjects[category].tasks || [];
tasks.forEach(task => floGlobals.allAvailableTasks.add(task.id))
}
for (const application in taskApplications) { for (const application in taskApplications) {
const { message: { taskID }, senderID } = taskApplications[application]; const { message: { taskID }, senderID } = taskApplications[application];
if (!floGlobals.applications[taskID]) if (!floGlobals.applications[taskID])
floGlobals.applications[taskID] = new Set() floGlobals.applications[taskID] = new Set()
floGlobals.applications[taskID].add(senderID) floGlobals.applications[taskID].add(senderID)
} }
} else if (floGlobals.isAdmin) { } else if (floGlobals.isAdmin) {
} else { } else {
@ -1296,11 +1317,16 @@ window.addEventListener("load", () => {
] ]
await Promise.all(promises) await Promise.all(promises)
const taskApplications = floDapps.getNextGeneralData('taskApplications', '0'); const taskApplications = floDapps.getNextGeneralData('taskApplications', '0');
floGlobals.allAvailableTasks = new Set();
for (const category in floGlobals.taskCategories) {
const tasks = floGlobals.appObjects[category].tasks || [];
tasks.forEach(task => floGlobals.allAvailableTasks.add(task.id))
}
for (const application in taskApplications) { for (const application in taskApplications) {
const { message: { taskID } } = taskApplications[application]; const { message: { taskID } } = taskApplications[application];
if ((floGlobals.appObjects.rmInterns.tasks || []).some(task => task.id === taskID)) { // if the task is still available, add it to the applications
if (floGlobals.allAvailableTasks.has(taskID))
floGlobals.applications.add(taskID) floGlobals.applications.add(taskID)
}
} }
const userProfile = floDapps.getNextGeneralData('userProfile', '0'); const userProfile = floDapps.getNextGeneralData('userProfile', '0');
floGlobals.userProfile = Object.values(userProfile).at(-1)?.message.encryptedData; floGlobals.userProfile = Object.values(userProfile).at(-1)?.message.encryptedData;

10
scripts/app.min.js vendored

File diff suppressed because one or more lines are too long