Skip to content

Commit

Permalink
feat: add daily log calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenull committed Jun 30, 2022
1 parent 0f74697 commit 714c480
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const App: React.FC<{
const [, setJournalEvents] = useAtom(journalEventsAtom)
const [, setProjectEvents] = useAtom(projectEventsAtom)

const { homePage = DEFAULT_SETTINGS.homePage } = getInitalSettings()
const { homePage = DEFAULT_SETTINGS.homePage, logKey } = getInitalSettings()
const homePageElement = MENUS.find(item => item.value === homePage)?.element
const menus = logKey?.enabled ? MENUS : MENUS.filter(item => item.value !== 'dailyLogCalendar')

useEffect(() => {
async function fetchSchedules() {
Expand All @@ -50,7 +51,7 @@ const App: React.FC<{
<Routes>
<Route path="/" element={homePageElement} />
{
MENUS.map(item => (
menus.map(item => (
<Route path={item.path} element={item.element} key={item.value} />
))
}
Expand Down
2 changes: 2 additions & 0 deletions src/constants/elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Stats from '@/pages/Stats'
import Settings from '@/pages/Settings'
import Journal from '@/pages/Journal'
import Review from '@/pages/Review'
import DailyLogCalendar from '@/pages/DailyLogCalendar'

export const MENUS = [
{ label: 'Dashboard', value: 'dashboard', icon: <MdOutlineDashboard />, path: '/dashboard', element: <Dashboard /> },
Expand All @@ -24,6 +25,7 @@ export const MENUS = [
{ label: 'Gantt', value: 'gantt', icon: <AiOutlineAlignLeft />, path: '/gantt', element: <Gantt /> },
{ label: 'Timeline', value: 'timeline', icon: <RiMenu4Line />, path: '/timeline', element: <Timeline /> },
{ label: 'Review', value: 'review', icon: <RiRecycleLine />, path: '/review', element: <Review /> },
{ label: 'Daily Log', value: 'dailyLogCalendar', icon: <RiRecycleLine />, path: '/dailyLogCalendar', element: <DailyLogCalendar /> },
// { label: 'Board', value: 'board', icon: <BsClipboardData />, path: '/board', element: <Board /> },
// { label: 'Journal', value: 'journal', icon: <IoJournalOutline />, path: '/journal', element: <Journal /> },
// { label: 'Stats', value: 'stats', icon: <FaChartArea />, path: '/stats', element: <Stats /> },
Expand Down
Empty file.
31 changes: 31 additions & 0 deletions src/pages/DailyLogCalendar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import classNames from 'classnames'

import CalendarCom from '@/components/Calendar'
import s from './index.module.less'
import { useEffect, useState } from 'react'
import { getDailyLogSchedules } from '@/util/schedule'

const index = () => {
const [dailyLogSchedules, setDailyLogSchedules] = useState<any[]>([])

useEffect(() => {
getDailyLogSchedules()
.then(res => {
setDailyLogSchedules(res)
})
}, [])

return (
<div className="page-container flex">
<div className={classNames('flex flex-1 flex-col overflow-hidden p-8')}>

<h1 className="title-text">Daily Log</h1>
<div className="bg-quaternary flex flex-col flex-1 rounded-2xl box-border p-6">
<CalendarCom schedules={dailyLogSchedules} isProjectCalendar={false} />
</div>
</div>
</div>
)
}

export default index
75 changes: 38 additions & 37 deletions src/util/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getCustomCalendarSchedules = async () => {

// get calendar configs
const settings = getInitalSettings()
const { calendarList: calendarConfigs = [], logKey, defaultDuration } = settings
const { calendarList: calendarConfigs = [] } = settings
const customCalendarConfigs = calendarConfigs.filter(config => config?.enabled)

let scheduleQueryList: IQueryWithCalendar[] = []
Expand Down Expand Up @@ -64,45 +64,46 @@ message: ${res.reason.message}`
})
calendarSchedules = flattenDeep(calendarSchedules.concat(scheduleResFulfilled))

// Daily Logs
if (logKey?.enabled) {
const logs = await logseq.DB.q(`[[${logKey.id}]]`)
// console.log('[faiz:] === search logs', logs)
const _logs = logs
?.filter(block => {
if (block.headingLevel && block.format === 'markdown') {
block.content = block.content.replace(new RegExp(`^#{${block.headingLevel}} `), '')
}
return block.content?.trim() === `[[${logKey.id}]]`
})
?.map(block => Array.isArray(block.parent) ? block.parent : [])
?.flat()
?.filter(block => {
const _content = block.content?.trim()
return _content.length > 0 && block?.page?.journalDay && !block.marker && !block.scheduled && !block.deadline
}) || []
const _logSchedulePromises = _logs?.map(async block => {
const date = block?.page?.journalDay
const { start: _startTime, end: _endTime } = getTimeInfo(block?.content.replace(new RegExp(`^${block.marker} `), ''))
const hasTime = _startTime || _endTime
return await genSchedule({
blockData: block,
category: hasTime ? 'time' : 'allday',
start: _startTime ? formatISO(parse(date + ' ' + _startTime, 'yyyyMMdd HH:mm', new Date())) : genCalendarDate(date),
end: _endTime ? formatISO(parse(date + ' ' + _endTime, 'yyyyMMdd HH:mm', new Date())) : undefined,
calendarConfig: logKey,
defaultDuration,
isAllDay: !hasTime,
isReadOnly: true,
})
})
const _logSchedules = await Promise.all(_logSchedulePromises)
calendarSchedules = calendarSchedules.concat(_logSchedules)
}

return calendarSchedules
}

export const getDailyLogSchedules = async () => {
const { logKey, defaultDuration } = getInitalSettings()
if (!logKey?.enabled) return []
const logs = await logseq.DB.q(`[[${logKey.id}]]`)
// console.log('[faiz:] === search logs', logs)
const _logs = logs
?.filter(block => {
if (block.headingLevel && block.format === 'markdown') {
block.content = block.content.replace(new RegExp(`^#{${block.headingLevel}} `), '')
}
return block.content?.trim() === `[[${logKey.id}]]`
})
?.map(block => Array.isArray(block.parent) ? block.parent : [])
?.flat()
?.filter(block => {
const _content = block.content?.trim()
return _content.length > 0 && block?.page?.journalDay && !block.marker && !block.scheduled && !block.deadline
}) || []
const _logSchedulePromises = _logs?.map(async block => {
const date = block?.page?.journalDay
const { start: _startTime, end: _endTime } = getTimeInfo(block?.content.replace(new RegExp(`^${block.marker} `), ''))
const hasTime = _startTime || _endTime
return await genSchedule({
blockData: block,
category: hasTime ? 'time' : 'allday',
start: _startTime ? formatISO(parse(date + ' ' + _startTime, 'yyyyMMdd HH:mm', new Date())) : genCalendarDate(date),
end: _endTime ? formatISO(parse(date + ' ' + _endTime, 'yyyyMMdd HH:mm', new Date())) : undefined,
calendarConfig: logKey,
defaultDuration,
isAllDay: !hasTime,
isReadOnly: true,
})
})
const _logSchedules = await Promise.all(_logSchedulePromises)
return _logSchedules
}

export const convertBlockToSchedule = async ({ block, queryWithCalendar, settings }: { block: any; queryWithCalendar: IQueryWithCalendar, settings: ISettingsForm }) => {
const { calendarConfig, query } = queryWithCalendar
const { script = '', scheduleStart = '', scheduleEnd = '', dateFormatter, isMilestone, queryType } = query
Expand Down

0 comments on commit 714c480

Please sign in to comment.