Add Sidepanel component for displaying task and calendar view
This commit is contained in:
parent
0d0855bbf9
commit
4a9f2263f2
5 changed files with 393 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import { useState } from 'react'
|
||||||
import { useQuery } from 'react-query'
|
import { useQuery } from 'react-query'
|
||||||
import { GetAllCircleMembers, GetAllUsers } from '../utils/Fetcher'
|
import { GetAllCircleMembers, GetAllUsers } from '../utils/Fetcher'
|
||||||
|
|
||||||
|
@ -6,5 +7,16 @@ export const useAllUsers = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useCircleMembers = () => {
|
export const useCircleMembers = () => {
|
||||||
return useQuery('allCircleMembers', GetAllCircleMembers)
|
const [refetchKey, setRefetchKey] = useState(0)
|
||||||
|
|
||||||
|
const { data, error, isLoading, refetch } = useQuery(
|
||||||
|
['allCircleMembers', refetchKey],
|
||||||
|
GetAllCircleMembers,
|
||||||
|
)
|
||||||
|
const handleRefetch = () => {
|
||||||
|
setRefetchKey(prevKey => prevKey + 1)
|
||||||
|
refetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
return { data, error, isLoading, handleRefetch }
|
||||||
}
|
}
|
||||||
|
|
91
src/views/Chores/Sidepanel.jsx
Normal file
91
src/views/Chores/Sidepanel.jsx
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
import { Box, Sheet } from '@mui/joy'
|
||||||
|
import { useMediaQuery } from '@mui/material'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { ChoresGrouper } from '../../utils/Chores'
|
||||||
|
import CalendarView from '../components/CalendarView'
|
||||||
|
|
||||||
|
const Sidepanel = ({ chores }) => {
|
||||||
|
const isLargeScreen = useMediaQuery(theme => theme.breakpoints.up('md'))
|
||||||
|
const [dueDatePieChartData, setDueDatePieChartData] = useState([])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setDueDatePieChartData(generateChoreDuePieChartData(chores))
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const generateChoreDuePieChartData = chores => {
|
||||||
|
const groups = ChoresGrouper('due_date', chores)
|
||||||
|
return groups
|
||||||
|
.map(group => {
|
||||||
|
return {
|
||||||
|
label: group.name,
|
||||||
|
value: group.content.length,
|
||||||
|
color: group.color,
|
||||||
|
id: group.name,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(item => item.value > 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLargeScreen) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Sheet
|
||||||
|
variant='outlined'
|
||||||
|
sx={{
|
||||||
|
p: 2,
|
||||||
|
// borderRadius: 'sm',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
mr: 10,
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
boxShadow: 'sm',
|
||||||
|
borderRadius: 20,
|
||||||
|
|
||||||
|
// minimum height to fit the content:
|
||||||
|
height: '80vh',
|
||||||
|
width: '290px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* <Box
|
||||||
|
sx={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PieChart width={200} height={200}>
|
||||||
|
<Pie
|
||||||
|
data={dueDatePieChartData}
|
||||||
|
dataKey='value'
|
||||||
|
nameKey='label'
|
||||||
|
innerRadius={30}
|
||||||
|
paddingAngle={5}
|
||||||
|
cornerRadius={5}
|
||||||
|
>
|
||||||
|
{dueDatePieChartData.map((entry, index) => (
|
||||||
|
<Cell key={`cell-${index}`} fill={entry.color} />
|
||||||
|
))}
|
||||||
|
</Pie>
|
||||||
|
|
||||||
|
<Legend
|
||||||
|
layout='horizontal'
|
||||||
|
align='center'
|
||||||
|
iconType='circle'
|
||||||
|
iconSize={8}
|
||||||
|
fontSize={12}
|
||||||
|
formatter={(label, value) => `${label}: ${value.payload.value}`}
|
||||||
|
wrapperStyle={{ paddingTop: 0, marginTop: 0 }} // Adjust padding and margin
|
||||||
|
/>
|
||||||
|
<Tooltip />
|
||||||
|
</PieChart>
|
||||||
|
</Box> */}
|
||||||
|
<Box sx={{ width: '100%' }}>
|
||||||
|
<CalendarView chores={chores} />
|
||||||
|
</Box>
|
||||||
|
</Sheet>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Sidepanel
|
79
src/views/components/Calendar.css
Normal file
79
src/views/components/Calendar.css
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
.react-calendar {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 600px;
|
||||||
|
font-family: 'Roboto', sans-serif;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-calendar__tile {
|
||||||
|
padding: 1em;
|
||||||
|
min-height: 3rem;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 8px;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
.react-calendar__tile:enabled:hover {
|
||||||
|
/* lighten existing color: ; */
|
||||||
|
background-color: rgba(0, 123, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-calendar__tile--active {
|
||||||
|
background-color: #007bff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Today's tile styles */
|
||||||
|
.react-calendar .react-calendar__tile--now {
|
||||||
|
/* More specific selector */
|
||||||
|
/* background-color: #4ec1a2e3; */
|
||||||
|
border: 2px dotted #4ec1a2e3;
|
||||||
|
border-radius: 8px; /* Consistent with other tiles */
|
||||||
|
background-color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-calendar .react-calendar__tile--now:enabled:hover {
|
||||||
|
background-color: rgba(0, 123, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure dot container doesn't break row height */
|
||||||
|
.dot-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 16px;
|
||||||
|
/* if more than 4 dot make them go to the new line: */
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
width: 0.3em;
|
||||||
|
height: 0.3em;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin: 0 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tooltip styles */
|
||||||
|
.dot-container {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chore-tooltip {
|
||||||
|
position: absolute;
|
||||||
|
top: 100%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
background-color: #333;
|
||||||
|
color: white;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 4px;
|
||||||
|
z-index: 10;
|
||||||
|
visibility: hidden;
|
||||||
|
opacity: 0;
|
||||||
|
transition:
|
||||||
|
opacity 0.2s ease,
|
||||||
|
visibility 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* remove different color on weekend: */
|
||||||
|
.react-calendar__month-view__days__day--weekend {
|
||||||
|
color: inherit;
|
||||||
|
}
|
176
src/views/components/CalendarView.jsx
Normal file
176
src/views/components/CalendarView.jsx
Normal file
|
@ -0,0 +1,176 @@
|
||||||
|
import { Box, Card, CardContent, Chip, Grid, Typography } from '@mui/joy'
|
||||||
|
import moment from 'moment'
|
||||||
|
import React, { useState } from 'react'
|
||||||
|
import Calendar from 'react-calendar'
|
||||||
|
import 'react-calendar/dist/Calendar.css'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { UserContext } from '../../contexts/UserContext'
|
||||||
|
import { getTextColorFromBackgroundColor, TASK_COLOR } from '../../utils/Colors'
|
||||||
|
import './Calendar.css'
|
||||||
|
|
||||||
|
const getAssigneeColor = (assignee, userProfile) => {
|
||||||
|
return assignee === userProfile.id
|
||||||
|
? TASK_COLOR.ASSIGNED_TO_ME
|
||||||
|
: TASK_COLOR.ASSIGNED_TO_OTHER
|
||||||
|
}
|
||||||
|
|
||||||
|
const CalendarView = ({ chores }) => {
|
||||||
|
const { userProfile } = React.useContext(UserContext)
|
||||||
|
const [selectedDate, setSeletedDate] = useState(null)
|
||||||
|
const Navigate = useNavigate()
|
||||||
|
|
||||||
|
const tileContent = ({ date, view }) => {
|
||||||
|
if (view === 'month') {
|
||||||
|
const dayChores = chores.filter(
|
||||||
|
chore =>
|
||||||
|
new Date(chore.nextDueDate)?.toISOString().split('T')[0] ===
|
||||||
|
date.toISOString().split('T')[0],
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='dot-container'>
|
||||||
|
{dayChores.map((chore, index) => {
|
||||||
|
if (index > 6) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
key={index}
|
||||||
|
className='dot'
|
||||||
|
style={{
|
||||||
|
backgroundColor: getAssigneeColor(
|
||||||
|
chore.assignedTo,
|
||||||
|
userProfile,
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
></span>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Calendar
|
||||||
|
tileContent={tileContent}
|
||||||
|
onChange={d => {
|
||||||
|
setSeletedDate(new Date(d))
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{!selectedDate && (
|
||||||
|
<Grid container ml={-3}>
|
||||||
|
{[
|
||||||
|
{ name: 'Assigned to me', color: TASK_COLOR.ASSIGNED_TO_ME },
|
||||||
|
{ name: 'Assigned to other', color: TASK_COLOR.ASSIGNED_TO_OTHER },
|
||||||
|
].map((item, index) => (
|
||||||
|
<Grid
|
||||||
|
key={index}
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
sx={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'start',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: 'inline-block',
|
||||||
|
width: 5,
|
||||||
|
height: 5,
|
||||||
|
borderRadius: '50%',
|
||||||
|
backgroundColor: item.color,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography level='body-xs' ml={0.3}>
|
||||||
|
{item.name}
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
))}
|
||||||
|
</Grid>
|
||||||
|
)}
|
||||||
|
{selectedDate && (
|
||||||
|
<Box
|
||||||
|
variant='outlined'
|
||||||
|
sx={{
|
||||||
|
// p: 2,
|
||||||
|
// borderRadius: 20,
|
||||||
|
// if exceed the height, scroll:
|
||||||
|
maxHeight: '160px',
|
||||||
|
overflowY: 'auto',
|
||||||
|
// minimum height to fit the content:
|
||||||
|
height: '50vh',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{chores
|
||||||
|
.filter(
|
||||||
|
chore =>
|
||||||
|
new Date(chore.nextDueDate)?.toISOString().split('T')[0] ===
|
||||||
|
selectedDate.toISOString().split('T')[0],
|
||||||
|
)
|
||||||
|
.map((chore, idx) => (
|
||||||
|
<Card
|
||||||
|
key={idx}
|
||||||
|
variant='soft'
|
||||||
|
onClick={() => {
|
||||||
|
Navigate('/chores/' + chore.id)
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
mb: 0.4,
|
||||||
|
py: 1,
|
||||||
|
px: 1,
|
||||||
|
|
||||||
|
// backgroundColor: getAssigneeColor(
|
||||||
|
// chore.assignedTo,
|
||||||
|
// userProfile,
|
||||||
|
// ),
|
||||||
|
// everything show in one row:
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CardContent>
|
||||||
|
<Typography
|
||||||
|
key={chore.id}
|
||||||
|
className='truncate'
|
||||||
|
maxWidth='100%'
|
||||||
|
>
|
||||||
|
<Chip
|
||||||
|
variant='plain'
|
||||||
|
size='sm'
|
||||||
|
sx={{
|
||||||
|
backgroundColor: getAssigneeColor(
|
||||||
|
chore.assignedTo,
|
||||||
|
userProfile,
|
||||||
|
),
|
||||||
|
mr: 0.5,
|
||||||
|
color: getTextColorFromBackgroundColor(
|
||||||
|
getAssigneeColor(chore.assignedTo, userProfile),
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{moment(chore.nextDueDate).format('hh:mm A')}
|
||||||
|
</Chip>
|
||||||
|
{chore.name}
|
||||||
|
</Typography>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CalendarView
|
34
src/views/components/IconButtonTouchable.jsx
Normal file
34
src/views/components/IconButtonTouchable.jsx
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import IconButton from '@mui/joy/IconButton'
|
||||||
|
import React, { useRef, useState } from 'react'
|
||||||
|
|
||||||
|
const IconButtonTouchable = ({ onHold, onClick, ...props }) => {
|
||||||
|
const [holdTimeout, setHoldTimeout] = useState(null)
|
||||||
|
const holdRef = useRef(false)
|
||||||
|
|
||||||
|
const handleMouseDown = () => {
|
||||||
|
holdRef.current = false
|
||||||
|
setHoldTimeout(
|
||||||
|
setTimeout(() => {
|
||||||
|
holdRef.current = true
|
||||||
|
onHold && onHold()
|
||||||
|
}, 1000),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMouseUp = () => {
|
||||||
|
clearTimeout(holdTimeout)
|
||||||
|
if (!holdRef.current) {
|
||||||
|
onClick && onClick()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
{...props}
|
||||||
|
onMouseDown={handleMouseDown}
|
||||||
|
onMouseUp={handleMouseUp}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IconButtonTouchable
|
Loading…
Add table
Reference in a new issue