Skip to content

Commit

Permalink
chore(app): remove some code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Feb 25, 2023
1 parent 81598f0 commit ac9744c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/components/MenuCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const MenuCard = ({ menu }) => {
}}
>
<List>
{links.map((link, index) => (
<Box key={`menu-child-${index}`}>
{links.map((link) => (
<Box key={`menu-child-${link.title}`}>
{link.visible && (
<ListItem disablePadding disabled={link.disabled}>
<ListItemButton onClick={() => handleAction(link)}>
Expand Down
4 changes: 1 addition & 3 deletions src/features/persons/PersonAdvancedSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ const StudentAdvancedSearch = ({
setIsCBSConductor(false);
setIsCBSReader(false);

for (let i = 0; i < assTypes.length; i++) {
const type = assTypes[i];

for (const type of assTypes) {
if (type === 110) setIsChairman(true);
if (type === 111) setIsPrayer(true);
if (type === 112) setIsTGWTalk(true);
Expand Down
8 changes: 4 additions & 4 deletions src/features/schedules/SchedulesByYear.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const SchedulesByYear = ({ year }) => {
const getMonthlySchedules = useCallback(async () => {
const data = await dbGetScheduleListByYear(year);
let newData = [];
for (let i = 0; i < data.length; i++) {
let obj = {};
obj.value = data[i].value;
const monthIndex = parseInt(data[i].value.split('/')[0], 10);
for (const item of data) {
const obj = {};
obj.value = item.value;
const monthIndex = parseInt(item.value.split('/')[0], 10);
obj.label = `${monthNames[monthIndex - 1]} ${year}`;
newData.push(obj);
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/schedules/StudentSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ const StudentSelector = (props) => {

// remove unavailable students based on time away
let available = [];
for (let a = 0; a < students.length; a++) {
const student = students[a];
for (const student of students) {
if (student.timeAway.length === 0) {
available.push(student);
} else {
const timeAways = student.timeAway;

for (let b = 0; b < timeAways.length; b++) {
const timeAway = timeAways[b];

Expand Down
8 changes: 4 additions & 4 deletions src/features/sourceMaterial/SourcesByYear.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const SourcesByYear = ({ year }) => {
const getMonthlySources = useCallback(async () => {
const data = await dbGetScheduleListByYear(year);
let newData = [];
for (let i = 0; i < data.length; i++) {
let obj = {};
obj.value = data[i].value;
const monthIndex = parseInt(data[i].value.split('/')[0], 10);
for (const item of data) {
const obj = {};
obj.value = item.value;
const monthIndex = parseInt(item.value.split('/')[0], 10);
obj.label = `${monthNames[monthIndex - 1]} ${year}`;
newData.push(obj);
}
Expand Down
3 changes: 1 addition & 2 deletions src/features/startup/pocket/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import {
isUnauthorizedRoleState,
visitorIDState,
} from '../../../states/main';
import { apiPocketValidate } from '../../../api';
import { apiFetchSchedule, apiPocketValidate } from '../../../api';
import { loadApp } from '../../../utils/app';
import { dbUpdateUserSettings } from '../../../indexedDb/dbAppSettings';
import { congAccountConnectedState } from '../../../states/congregation';
import { runUpdater } from '../../../utils/updater';
import { apiFetchSchedule } from '../../../api';

// lazy loading
const PocketSignUp = lazy(() => import('./PocketSignUp'));
Expand Down
1 change: 0 additions & 1 deletion src/features/startup/vip/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const VipStartup = () => {
setIsSetup(false);
setIsAppLoad(false);
}, [1000]);
return;
}
};

Expand Down
31 changes: 17 additions & 14 deletions src/indexedDb/dbAssignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export const dbGetListAssType = async () => {
let obj = {};
const appData = await appDb.table('assignment').reverse().reverse().sortBy('code');

for (let i = 0; i < appData.length; i++) {
for (const item of appData) {
obj = {};
obj.code = appData[i].code;
obj.assignable = appData[i].assignable;
obj.assignment_type_name = appData[i].assignment_type_name;
obj.maleOnly = appData[i].maleOnly || false;
obj.type = appData[i].type;
obj.linkTo = appData[i].linkTo;
obj.code = item.code;
obj.assignable = item.assignable;
obj.assignment_type_name = item.assignment_type_name;
obj.maleOnly = item.maleOnly || false;
obj.type = item.type;
obj.linkTo = item.linkTo;
assType.push(obj);
}
return assType;
Expand Down Expand Up @@ -84,18 +84,19 @@ export const dbHistoryAssignment = async () => {

if (persons > 0) {
let histID = 0;
for (let i = 0; i < appData.length; i++) {

for await (const schedule of appData) {
let person = {};

const weekData = await dbGetSourceMaterial(appData[i].weekOf);
const [varMonth, varDay, varYear] = appData[i].weekOf.split('/');
const weekData = await dbGetSourceMaterial(schedule.weekOf);
const [varMonth, varDay, varYear] = schedule.weekOf.split('/');
const lDate = new Date(varYear, varMonth - 1, varDay);
const shortDateFormat = await promiseGetRecoil(shortDateFormatState);
const dateFormatted = dateFormat(lDate, shortDateFormat);

const assList = [];
const excludeFiles = ['weekOf', 'week_type', 'noMeeting', 'isReleased', 'changes'];
for (const [key, value] of Object.entries(appData[i])) {
for (const [key, value] of Object.entries(schedule)) {
if (excludeFiles.indexOf(key) === -1 && key.indexOf('_name') === -1 && key.indexOf('_dispName') === -1) {
if (value && value !== '') {
assList.push({ assignment: key, person: value });
Expand All @@ -105,7 +106,7 @@ export const dbHistoryAssignment = async () => {

for await (const item of assList) {
person.ID = histID;
person.weekOf = appData[i].weekOf;
person.weekOf = schedule.weekOf;
person.weekOfFormatted = dateFormatted;
person.studentID = item.person;
const stuDetails = await dbGetStudentByUid(item.person);
Expand Down Expand Up @@ -224,6 +225,7 @@ export const dbHistoryAssignment = async () => {
histID++;
}
}

dbHistory.sort((a, b) => {
const dateA = a.weekOf.split('/')[2] + '/' + a.weekOf.split('/')[0] + '/' + a.weekOf.split('/')[1];
const dateB = b.weekOf.split('/')[2] + '/' + b.weekOf.split('/')[0] + '/' + b.weekOf.split('/')[1];
Expand Down Expand Up @@ -562,8 +564,8 @@ export const dbGetS89WeekList = async (scheduleName) => {
const s89Data = [];
const allWeeks = await dbGetWeekListBySched(scheduleName);

for (let i = 0; i < allWeeks.length; i++) {
const week = allWeeks[i].value;
for await (const item of allWeeks) {
const week = item.value;
const scheduleData = await dbGetScheduleData(week);
if (!scheduleData.noMeeting) {
const parentWeek = {};
Expand Down Expand Up @@ -636,6 +638,7 @@ export const dbGetS89WeekList = async (scheduleName) => {
}
}
}

const obj = {};
obj.value = 'S89';
obj.label = getI18n().t('allWeeks', { ns: 'ui' });
Expand Down
6 changes: 4 additions & 2 deletions src/states/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export const isStudentDetailsOpenState = selector({
const isAdd = get(isStudentAddState);
const isEdit = get(isStudentEditState);

let isDetailOpen = true;

if (!isAdd && !isEdit) {
return false;
isDetailOpen = false;
}

return true;
return isDetailOpen;
},
});

Expand Down

0 comments on commit ac9744c

Please sign in to comment.