Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit 52838a9

Browse files
committed
fix: data-handling utilization
1 parent 9aea403 commit 52838a9

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

src/pages/DataRefresh.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import employees from '../data/EmployeeData.json';
33
import finances from '../data/FinanceData.json';
44
import projects from '../data/ProjectData.json';
55
import tasks from '../data/TaskData.json';
6+
import { SetItem } from '../functions/ArrayData';
67

78
export const DataRefresh = () => {
89
function saveData() {
9-
localStorage.setItem('employees', JSON.stringify(employees));
10-
localStorage.setItem('finances', JSON.stringify(finances));
11-
localStorage.setItem('projects', JSON.stringify(projects));
12-
localStorage.setItem('tasks', JSON.stringify(tasks));
10+
SetItem('employees', employees);
11+
SetItem('finances', finances);
12+
SetItem('projects', projects);
13+
SetItem('tasks', tasks);
1314
}
1415

1516
return (

src/pages/SM.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import ProjectInterface from "../interfaces/ProjectInterface";
55
import EmployeeInterface from "../interfaces/EmployeeInterface";
66
import StatusOptions from "../interfaces/StatusOptions";
77
import FinanceInterface from "../interfaces/FinanceInterface";
8+
import PageName from "../functions/PageName";
9+
import { GetItem, SetItem } from "../functions/ArrayData";
810

911
export const SM = () => {
1012
const [tasks, setTasks] = useState<TaskInterface[]>([]);
@@ -13,14 +15,15 @@ export const SM = () => {
1315
const [finances, setFinances] = useState<FinanceInterface[]>([]);
1416

1517
useEffect(() => {
16-
const tasks = JSON.parse(localStorage.getItem('tasks') || '[]');
18+
const tasks = GetItem('tasks');
1719
setTasks(tasks);
18-
const projects = JSON.parse(localStorage.getItem('projects') || '[]');
20+
const projects = GetItem('projects');
1921
setProjects(projects);
20-
const employees = JSON.parse(localStorage.getItem('employees') || '[]');
22+
const employees = GetItem('employees');
2123
setEmployees(employees);
22-
const finances = JSON.parse(localStorage.getItem('finances') || '[]');
24+
const finances = GetItem('finances');
2325
setFinances(finances);
26+
PageName('SM');
2427
}, []);
2528

2629
const [newTask, setNewTask] = useState('');
@@ -42,16 +45,16 @@ export const SM = () => {
4245
setNewTaskDescription('');
4346
setNewTaskProjectID('');
4447
setNewTaskEmployeeID('');
45-
localStorage.setItem('tasks', JSON.stringify(tasks));
48+
SetItem('tasks', tasks);
4649
};
4750

4851
return (
4952
<div>
5053
<h1>SM</h1>
51-
<ul>
54+
<ul className="m-5">
5255
{
53-
employees.map((employee: EmployeeInterface) => (
54-
<li key={employee.employee_id} className="bg-gray-50 m-3">
56+
employees.map((employee: EmployeeInterface, index) => (
57+
<li key={index} className="m-3">
5558
{employee.name}
5659
|
5760
{
@@ -64,10 +67,10 @@ export const SM = () => {
6467
))
6568
}
6669
</ul>
67-
<ul>
70+
<ul className="m-5">
6871
{
69-
projects.map((project: ProjectInterface) => (
70-
<li key={project.project_id} className="bg-blue-50 m-3">
72+
projects.map((project: ProjectInterface, index) => (
73+
<li key={index} className=" m-3">
7174
{project.name}
7275
|
7376
({
@@ -88,9 +91,9 @@ export const SM = () => {
8891
))
8992
}
9093
</ul>
91-
<ul>
92-
{tasks.map((task: TaskInterface) => (
93-
<div key={task.task_id} className='flex flex-col bg-red-50 m-3'>
94+
<ul className="m-5">
95+
{tasks.map((task: TaskInterface, index) => (
96+
<div key={index} className='flex flex-col m-3'>
9497
<p>{task.title}</p>
9598
<p>{task.description}</p>
9699
<p>{task.status}</p>
@@ -121,21 +124,21 @@ export const SM = () => {
121124
<Select value={newTaskStatus} onChange={(e) => setNewTaskStatus(e.target.value)}>
122125
<option value="">Select Status</option>
123126
{
124-
StatusOptions.map((status: string) => (
125-
<option value={status}>{status}</option>
127+
StatusOptions.map((status: string, index) => (
128+
<option key={index} value={status}>{status}</option>
126129
))
127130
}
128131
</Select>
129132
<Select value={newTaskProjectID} onChange={(e) => setNewTaskProjectID(e.target.value)}>
130133
<option value="">Select Project</option>
131-
{projects.map((project: ProjectInterface) => (
132-
<option value={project.project_id}>{project.name}</option>
134+
{projects.map((project: ProjectInterface, index) => (
135+
<option key={index} value={project.project_id}>{project.name}</option>
133136
))}
134137
</Select>
135138
<Select value={newTaskEmployeeID} onChange={(e) => setNewTaskEmployeeID(e.target.value)}>
136139
<option value="">Select Employee</option>
137-
{employees.map((employee: EmployeeInterface) => (
138-
<option value={employee.employee_id}>{employee.name}</option>
140+
{employees.map((employee: EmployeeInterface, index) => (
141+
<option key={index} value={employee.employee_id}>{employee.name}</option>
139142
))}
140143
</Select>
141144
<Button onClick={addTask}>

0 commit comments

Comments
 (0)