Skip to content

Commit ed49062

Browse files
Shreya AgrawalShreya Agrawal
authored andcommitted
ui fix for year handlers
1 parent 1b84636 commit ed49062

File tree

4 files changed

+63
-10
lines changed

4 files changed

+63
-10
lines changed

client/src/screens/browse/components/year-info/confirmDialog.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const ConfirmDialog = ({
3030
confirmText = "Confirm",
3131
cancelText = "Cancel",
3232
}) => {
33-
const [submitEnabled, setSubmitEnabled] = useState(true);
33+
const [submitEnabled, setSubmitEnabled] = useState(false);
3434
if (!show) return null;
3535

3636
return (
@@ -50,7 +50,11 @@ const ConfirmDialog = ({
5050
name="section"
5151
className="select_section"
5252
value={yearName}
53-
onChange={(e) => onYearNameChange(e.target.value)}
53+
onChange={(e) => {
54+
if (e.target.value) setSubmitEnabled(true);
55+
else setSubmitEnabled(false);
56+
onYearNameChange(e.target.value);
57+
}}
5458
>
5559
<option value="" disabled>
5660
Select year

client/src/screens/browse/components/year-info/index.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const YearInfo = ({
2828
const handleConfirmAddYear = async () => {
2929
const yearName = newYearName.trim();
3030

31+
if(!yearName) return;
32+
console.log(yearName);
3133
if (!courseCode) {
3234
toast.error("No course selected.");
3335
return;
@@ -94,7 +96,11 @@ const YearInfo = ({
9496
key={idx}
9597
>
9698
{year.name}
97-
<div className="delete" onClick={handleDeleteYear}></div>
99+
<div
100+
className="delete"
101+
onClick={handleDeleteYear}
102+
title="Delete Year"
103+
></div>
98104

99105
</span>
100106
<ConfirmDelDialog
@@ -112,7 +118,7 @@ const YearInfo = ({
112118
<div>
113119
<div className="">
114120
<span className="" onClick={handleAddYear}>
115-
<span className="text">Add Year</span>
121+
<span className="text">New Year</span>
116122
</span>
117123
</div>
118124
<ConfirmDialog

client/src/screens/browse/components/year-info/year-options.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const presentYears=[];
22
const options=[];
3-
const currYear=new Date().getFullYear();
3+
const currentDate = new Date();
4+
const currentMonth = currentDate.getMonth() + 1; // getMonth() returns 0-11, so add 1 for 1-12
5+
const acadYear = (currentMonth >= 1 && currentMonth <= 5) ? currentDate.getFullYear() - 1 : currentDate.getFullYear();
46
for(let i=0;i<5;i++){
5-
let yr=(currYear-i).toString();
7+
let yr=(acadYear-i).toString();
68
if(!presentYears.includes(yr))
79
options.push(yr);
810
}

client/src/screens/browse/styles.scss

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,57 @@
5555
font-size: 1.2rem;
5656
}
5757
.year{
58+
cursor: pointer;
5859
padding: 10px 20px;
5960
font-size: 1.14rem;
61+
position: relative;
62+
display: flex;
63+
align-items: center;
64+
justify-content: space-between;
6065
&.selected{
6166
color: #000;
6267
background-color: #fff;
6368
.delete{
64-
background-color: red;
65-
height:15px;
66-
width: 15px;
67-
border-radius: 50%;
69+
background: url(./components/browsefolder/Delete.svg), none;
70+
71+
position: absolute;
72+
top: 50%;
73+
right: 10px;
74+
transform: translateY(-50%);
75+
width: 16px;
76+
height: 16px;
77+
background-size: contain;
78+
background-repeat: no-repeat;
79+
background-position: center;
80+
cursor: pointer;
81+
opacity: 0;
82+
transition: opacity 0.2s ease-in-out;
83+
z-index: 3;
84+
border-radius: 2px;
85+
}
86+
}
87+
&.selected:hover .delete{opacity: 1;}
88+
}
89+
&.add-year {
90+
border-top: 1px solid #333;
91+
margin-top: 10px;
92+
padding: 10px 20px;
93+
94+
span {
95+
color: #888;
96+
font-size: 0.9rem;
97+
cursor: pointer;
98+
transition: color 0.2s ease-in-out;
99+
100+
&:hover {
101+
color: #bbb;
102+
}
103+
104+
.text {
105+
&::before {
106+
content: "+ ";
107+
margin-right: 4px;
108+
}
68109
}
69110
}
70111
}

0 commit comments

Comments
 (0)