HyeonJun Jeon

[Add] Schedule finish button

1 const express = require("express"); 1 const express = require("express");
2 +const mysql2 = require("mysql2/promise");
3 +const { connectOption } = require("../libs/MySQL");
2 const dbRouter = express.Router(); 4 const dbRouter = express.Router();
3 5
4 const schedules_dateRouter = require("./schedules_date"); 6 const schedules_dateRouter = require("./schedules_date");
...@@ -9,6 +11,25 @@ const userSubjectRouter = require("./user-subject"); ...@@ -9,6 +11,25 @@ const userSubjectRouter = require("./user-subject");
9 const usersRouter = require("./Users"); 11 const usersRouter = require("./Users");
10 12
11 async function route() { 13 async function route() {
14 + const connection = await mysql2.createConnection(connectOption);
15 +
16 + // (userID, uid)
17 + dbRouter.delete("/schedule", async (req, res) => {
18 + console.log("delete /db/schedule");
19 + try {
20 + const queryString = `
21 + DELETE FROM \`${req.body.table}\` sc
22 + WHERE sc.userID = ${req.body.userID}
23 + AND sc.uid = ${req.body.uid}`;
24 + const [result] = await connection.query(queryString);
25 + console.log(req.body);
26 + res.end();
27 + } catch (e) {
28 + console.log(e);
29 + res.end();
30 + }
31 + });
32 +
12 dbRouter.use("/user-subject", userSubjectRouter); 33 dbRouter.use("/user-subject", userSubjectRouter);
13 dbRouter.use("/users", usersRouter); 34 dbRouter.use("/users", usersRouter);
14 dbRouter.use("/subjects", subjectsRouter); 35 dbRouter.use("/subjects", subjectsRouter);
......
...@@ -11,7 +11,8 @@ async function route() { ...@@ -11,7 +11,8 @@ async function route() {
11 // console.log("/db/schedules_date"); 11 // console.log("/db/schedules_date");
12 try { 12 try {
13 const queryString = ` 13 const queryString = `
14 - SELECT sc.label, sc.type, sc.description, sc.url, sc.detail, sbj.name, us.nickname, us.color, sc.uid 14 + SELECT sc.label, sc.type, sc.description, sc.url, sc.detail,
15 + sbj.name, us.nickname, us.color, sc.uid, "schedules_date" \`table\`
15 FROM schedules_date sc 16 FROM schedules_date sc
16 INNER JOIN \`user-subject\` us 17 INNER JOIN \`user-subject\` us
17 ON sc.userID = us.userID 18 ON sc.userID = us.userID
......
...@@ -11,7 +11,8 @@ async function route() { ...@@ -11,7 +11,8 @@ async function route() {
11 // console.log("/db/schedules_repeat"); 11 // console.log("/db/schedules_repeat");
12 try { 12 try {
13 const queryString = ` 13 const queryString = `
14 - SELECT sc.label, sc.type, sc.description, sc.uid, sc.url, sc.detail, sbj.name, us.nickname, us.color, sc.startTime, sc.endTime 14 + SELECT sc.label, sc.type, sc.description, sc.uid, sc.url, sc.detail, sbj.name,
15 + us.nickname, us.color, sc.startTime, sc.endTime, "schedules_repeat" \`table\`
15 FROM schedules_repeat sc 16 FROM schedules_repeat sc
16 INNER JOIN \`user-subject\` us 17 INNER JOIN \`user-subject\` us
17 ON sc.userID = us.userID 18 ON sc.userID = us.userID
......
...@@ -11,7 +11,8 @@ async function route() { ...@@ -11,7 +11,8 @@ async function route() {
11 // console.log("/db/schedules_time"); 11 // console.log("/db/schedules_time");
12 try { 12 try {
13 const queryString = ` 13 const queryString = `
14 - SELECT sc.label, sc.type, sc.description, sc.url, sc.detail, sbj.name, us.nickname, us.color, sc.uid, sc.startTime, sc.endTime 14 + SELECT sc.label, sc.type, sc.description, sc.url, sc.detail, sbj.name, us.nickname,
15 + us.color, sc.uid, sc.startTime, sc.endTime, "schedules_time" \`table\`
15 FROM schedules_time sc 16 FROM schedules_time sc
16 INNER JOIN \`user-subject\` us 17 INNER JOIN \`user-subject\` us
17 ON sc.userID = us.userID 18 ON sc.userID = us.userID
......
...@@ -37,6 +37,21 @@ const GridItem = ({ targetDate }) => { ...@@ -37,6 +37,21 @@ const GridItem = ({ targetDate }) => {
37 loadScheduleItems(); 37 loadScheduleItems();
38 }, [targetDate]); 38 }, [targetDate]);
39 39
40 + const finishSchedule = async (table, uid) => {
41 + for (const i in schedules)
42 + if (schedules[i].uid === uid) {
43 + await axios.delete("http://localhost:3001/db/schedule", {
44 + data: {
45 + table,
46 + uid,
47 + userID: await localforage.getItem("userID"),
48 + },
49 + });
50 + schedules.splice(i, 1);
51 + setSchedules(schedules);
52 + }
53 + };
54 +
40 return ( 55 return (
41 <div className="GridItem" relative={month - calMonth || null}> 56 <div className="GridItem" relative={month - calMonth || null}>
42 <span className="date"> 57 <span className="date">
...@@ -44,7 +59,7 @@ const GridItem = ({ targetDate }) => { ...@@ -44,7 +59,7 @@ const GridItem = ({ targetDate }) => {
44 </span> 59 </span>
45 {schedules && 60 {schedules &&
46 schedules.map((sche, index) => ( 61 schedules.map((sche, index) => (
47 - <ScheduleItem key={index} schedule={sche} /> 62 + <ScheduleItem key={index} schedule={sche} finish={finishSchedule} />
48 ))} 63 ))}
49 </div> 64 </div>
50 ); 65 );
......
1 +import { useRef } from "react";
1 import zoomSymbol from "../assets/zoom.png"; 2 import zoomSymbol from "../assets/zoom.png";
2 import ecampusSymbol from "../assets/e-Campus.png"; 3 import ecampusSymbol from "../assets/e-Campus.png";
3 -import { useRef } from "react";
4 4
5 -const ScheduleItem = ({ schedule }) => { 5 +const ScheduleItem = ({ schedule, finish }) => {
6 const { 6 const {
7 name: subjectName, 7 name: subjectName,
8 nickname: subjectNickname, 8 nickname: subjectNickname,
...@@ -15,6 +15,7 @@ const ScheduleItem = ({ schedule }) => { ...@@ -15,6 +15,7 @@ const ScheduleItem = ({ schedule }) => {
15 detail = null, 15 detail = null,
16 startTime = null, //HHMMSS문자열 16 startTime = null, //HHMMSS문자열
17 endTime = null, 17 endTime = null,
18 + table,
18 } = schedule; 19 } = schedule;
19 let sTime = startTime ? startTime.substring(0, 5) : ""; //HHMM 20 let sTime = startTime ? startTime.substring(0, 5) : ""; //HHMM
20 let eTime = endTime ? endTime.substring(0, 5) : ""; 21 let eTime = endTime ? endTime.substring(0, 5) : "";
...@@ -34,12 +35,18 @@ const ScheduleItem = ({ schedule }) => { ...@@ -34,12 +35,18 @@ const ScheduleItem = ({ schedule }) => {
34 }; 35 };
35 36
36 const popupRef = useRef(); 37 const popupRef = useRef();
38 + const thisRef = useRef();
37 39
38 const click = (e) => { 40 const click = (e) => {
41 + //Item
39 if (e.target.classList.contains("ss")) 42 if (e.target.classList.contains("ss"))
40 popupRef.current.style.display = "grid"; 43 popupRef.current.style.display = "grid";
41 else { 44 else {
42 - if (e.target.className === "spc") popupRef.current.style.display = "none"; 45 + if (e.target.className === "spc") popupRef.current.style.display = "none"; //popup close
46 + if (e.target.className === "spd") {
47 + finish(table, scheUID);
48 + thisRef.current.style.display = "none";
49 + }
43 } 50 }
44 }; 51 };
45 52
...@@ -48,6 +55,7 @@ const ScheduleItem = ({ schedule }) => { ...@@ -48,6 +55,7 @@ const ScheduleItem = ({ schedule }) => {
48 className="ScheduleItem ss" 55 className="ScheduleItem ss"
49 style={{ borderColor: "#" + subjectColor }} 56 style={{ borderColor: "#" + subjectColor }}
50 onClick={click} 57 onClick={click}
58 + ref={thisRef}
51 > 59 >
52 <img className="s_symbol ss" src={selectSymbol()} alt="404" /> 60 <img className="s_symbol ss" src={selectSymbol()} alt="404" />
53 {startTime && <span className="s_start ss">{sTime}</span>} 61 {startTime && <span className="s_start ss">{sTime}</span>}
...@@ -68,9 +76,12 @@ const ScheduleItem = ({ schedule }) => { ...@@ -68,9 +76,12 @@ const ScheduleItem = ({ schedule }) => {
68 {description && <span>{description}</span>} 76 {description && <span>{description}</span>}
69 {detail && <div dangerouslySetInnerHTML={{ __html: detail }}></div>} 77 {detail && <div dangerouslySetInnerHTML={{ __html: detail }}></div>}
70 </div> 78 </div>
79 + <div className="sp_btn">
80 + <button className="spd">완료</button>
71 <button className="spc">닫기</button> 81 <button className="spc">닫기</button>
72 </div> 82 </div>
73 </div> 83 </div>
84 + </div>
74 ); 85 );
75 }; 86 };
76 87
......
...@@ -122,9 +122,14 @@ button:disabled { ...@@ -122,9 +122,14 @@ button:disabled {
122 width: calc(100% - 2px); 122 width: calc(100% - 2px);
123 } 123 }
124 124
125 -.spc { 125 +.sp_btn {
126 + display: flex;
127 + margin-left: calc(100% - 100px);
128 +}
129 +
130 +.sp_btn > button {
131 + margin-left: 2px;
126 margin-top: 2px; 132 margin-top: 2px;
127 - margin-left: calc(100% - 50px);
128 width: 50px; 133 width: 50px;
129 height: 35px; 134 height: 35px;
130 cursor: pointer; 135 cursor: pointer;
......