Skip to content

Commit

Permalink
feat: ✨ [skip ci]add default calendar query
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenull committed Mar 3, 2022
1 parent acf9d2d commit 83c64c5
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 78 deletions.
31 changes: 31 additions & 0 deletions src/components/CreateCalendarModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Form, Input, Modal } from 'antd'
import React, { useState } from 'react'

const CreateCalendarModal: React.FC<{
visible: boolean
onSave: (name: string) => void
onCancel: () => void
}> = ({ visible, onCancel, onSave }) => {
const [form] = Form.useForm()

return (
<Modal
title="Create Calendar"
visible={visible}
onOk={() => {
form.validateFields().then(values => {
onSave(values.calendarId.trim())
})
}}
onCancel={onCancel}
>
<Form form={form}>
<Form.Item name="calendarId" label="Calendar ID" rules={[{required: true}]}>
<Input />
</Form.Item>
</Form>
</Modal>
)
}

export default CreateCalendarModal
45 changes: 28 additions & 17 deletions src/components/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { useState } from 'react'
import { Modal, Form, Select, Input, Button, Switch } from 'antd'
import { QuestionCircleOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'
import { getInitalSettings, ISettingsForm, ISettingsFormQuery } from '../util/util'
import { genDefaultQuery, getInitalSettings, ISettingsForm, ISettingsFormQuery } from '../util/util'
import { useForm } from 'antd/lib/form/Form'
import ColorPicker from './ColorPicker'
import { CALENDAR_VIEWS } from '../util/constants'
import Query from './Query'
import CreateCalendarModal from './CreateCalendarModal'


const initialValues = getInitalSettings()
const Settings: React.FC<{
visible: boolean
onCancel: () => void
Expand All @@ -16,23 +18,24 @@ const Settings: React.FC<{
}> = ({ visible, onCancel, onOk, ...props }) => {
const [settingForm] = useForm<ISettingsForm>()

const [createCalendarModalVisible, setCreateCalendarModalVisible] = useState(false)

console.log('[faiz:] === initialValues settings', initialValues)

const onClickSettingSave = () => {
settingForm.validateFields().then(values => {
onOk(values)
// if (values.weekStartDay !== logseq.settings?.weekStartDay) {
// calendarRef.current?.setOptions({
// week: {
// startDayOfWeek: values.weekStartDay,
// },
// month: {
// startDayOfWeek: values.weekStartDay,
// },
// })
// }
// if (values.logKey !== logseq.settings?.logKey) setSchedules()
// logseq.updateSettings(values)
})
}
const onCreateCalendarModalOk = (calendarId: string) => {
settingForm.setFieldsValue({
calendarList: [
...settingForm.getFieldValue('calendarList'),
genDefaultQuery(calendarId),
]
})
setCreateCalendarModalVisible(false)
}

return (
<>
Expand All @@ -46,7 +49,7 @@ const Settings: React.FC<{
onCancel={onCancel}
onOk={onClickSettingSave}
>
<Form initialValues={getInitalSettings()} form={settingForm} labelCol={{ span: 7 }} preserve={false}>
<Form initialValues={initialValues} labelCol={{ span: 7 }} preserve={false} form={settingForm} onValuesChange={(value) => console.log('[faiz:] === onValuesChange', value)}>
<Form.Item label="Default View" name="defaultView" rules={[{ required: true }]}>
<Select options={CALENDAR_VIEWS} />
</Form.Item>
Expand Down Expand Up @@ -83,23 +86,31 @@ const Settings: React.FC<{
<ColorPicker text="border" />
</Form.Item>
<Form.Item name={[field.name, 'query']} noStyle rules={[{ required: true }]}>
<Query calendarId='' />
<Query calendarId='query' />
</Form.Item>
<Form.Item name={[field.name, 'enabled']} noStyle valuePropName="checked">
<Switch size="small" />
</Form.Item>
{index !== 0 ? <MinusCircleOutlined onClick={() => remove(field.name)} /> : <div style={{ width: '14px' }}></div>}
{index !== 0 ? <MinusCircleOutlined onClick={() => {
console.log('[faiz:] === remove', field.name, field)
remove(field.name)
}} /> : <div style={{ width: '14px' }}></div>}
</div>
</Form.Item>
))}
<Form.Item wrapperCol={{ offset: 7 }}>
<Button type="dashed" size="small" onClick={() => add()} block icon={<PlusOutlined />}>
<Button type="dashed" size="small" onClick={() => setCreateCalendarModalVisible(true)} block icon={<PlusOutlined />}>
Add Calendar
</Button>
</Form.Item>
</>)}
</Form.List>
</Form>
<CreateCalendarModal
visible={createCalendarModalVisible}
onSave={onCreateCalendarModalOk}
onCancel={() => setCreateCalendarModalVisible(false)}
/>
</Modal>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (isDevelopment) {

logseq.App.registerUIItem('toolbar', {
key: 'logseq-plugin-agenda',
template: '<a data-on-click="show" class="button"><i class="ti ti-window"></i></a>',
template: '<a data-on-click="show" class="button"><i class="ti ti-comet"></i></a>',
})

window.faizNavigate = (e) => {
Expand Down
212 changes: 152 additions & 60 deletions src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ export const DEFAULT_JOURNAL_FORMAT = 'YYYY-MM-DD ddd'

export const DEFAULT_LOG_KEY = 'Daily Log'

// [(get-else $ ?block :block/scheduled "nil") ?d]
// [(not= ?d "nil")]

export const CALENDAR_VIEWS = [
{ value: 'day', label: 'Daily' },
{ value: 'week', label: 'Weekly' },
Expand All @@ -32,84 +29,179 @@ export const DEFAULT_SETTINGS: ISettingsForm = {
// schedule tasks
{
script: `
[:find (pull ?block [*])
:where
[?block :block/marker ?marker]
[(missing? $ ?block :block/deadline)]
(not [(missing? $ ?block :block/scheduled)])
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
[:find (pull ?block [*])
:where
[?block :block/marker ?marker]
[(missing? $ ?block :block/deadline)]
(not [(missing? $ ?block :block/scheduled)])
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
`,
scheduleStart: 'scheduled',
dateFormatter: 'YYYYMMDD',
},
// deadline tasks
{
script: `
[:find (pull ?block [*])
:where
[?block :block/marker ?marker]
[(missing? $ ?block :block/scheduled)]
[(get-else $ ?block :block/deadline "nil") ?d]
[(not= ?d "nil")]
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
`,
scheduleStart: 'deadline',
dateFormatter: 'YYYYMMDD',
},
// tasks with no deadline or scheduled but in journal
{
script: `
[:find (pull
?block
[:block/uuid
:block/parent
:block/left
:block/collapsed?
:block/format
:block/_refs
:block/path-refs
:block/tags
:block/content
:block/marker
:block/priority
:block/properties
:block/pre-block?
:block/scheduled
:block/deadline
:block/repeated?
:block/created-at
:block/updated-at
:block/file
:block/heading-level
{:block/page
[:db/id :block/name :block/original-name :block/journal-day :block/journal?]}])
:where
[?block :block/page ?page]
[?page :block/journal? true]
[?block :block/marker ?marker]
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]
[(missing? $ ?block :block/scheduled)]
[(missing? $ ?block :block/deadline)]]
`,
scheduleStart: 'page.journal-day',
dateFormatter: 'YYYYMMDD',
},
// milestone
{
script: `
[:find (pull ?block [*])
:where
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[?rp :block/name "milestone"]
[?block :block/refs ?rp]]
`,
scheduleStart: 'scheduled',
dateFormatter: 'YYYYMMDD',
isMilestone: true,
}
],
},
{
id: 'xxxxx',
bgColor: '#047857',
textColor: '#fff',
borderColor: '#047857',
enabled: true,
query: [
// schedule tasks
{
script: `
[:find (pull ?block [*])
:where
[?block :block/marker ?marker]
[(missing? $ ?block :block/deadline)]
(not [(missing? $ ?block :block/scheduled)])
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
`,
scheduleStart: 'scheduled',
dateFormatter: 'YYYYMMDD',
},
// deadline tasks
{
script: `
[:find (pull ?block [*])
:where
[?block :block/marker ?marker]
[(missing? $ ?block :block/scheduled)]
[(get-else $ ?block :block/deadline "nil") ?d]
[(not= ?d "nil")]
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
[:find (pull ?block [*])
:where
[?block :block/marker ?marker]
[(missing? $ ?block :block/scheduled)]
[(get-else $ ?block :block/deadline "nil") ?d]
[(not= ?d "nil")]
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
`,
scheduleStart: 'deadline',
dateFormatter: 'YYYYMMDD',
},
// tasks with no deadline or scheduled but in journal
{
script: `
[:find (pull
?block
[:block/uuid
:block/parent
:block/left
:block/collapsed?
:block/format
:block/_refs
:block/path-refs
:block/tags
:block/content
:block/marker
:block/priority
:block/properties
:block/pre-block?
:block/scheduled
:block/deadline
:block/repeated?
:block/created-at
:block/updated-at
:block/file
:block/heading-level
{:block/page
[:db/id :block/name :block/original-name :block/journal-day :block/journal?]}])
:where
[?block :block/page ?page]
[?page :block/journal? true]
[?block :block/marker ?marker]
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]
[(missing? $ ?block :block/scheduled)]
[(missing? $ ?block :block/deadline)]]
[:find (pull
?block
[:block/uuid
:block/parent
:block/left
:block/collapsed?
:block/format
:block/_refs
:block/path-refs
:block/tags
:block/content
:block/marker
:block/priority
:block/properties
:block/pre-block?
:block/scheduled
:block/deadline
:block/repeated?
:block/created-at
:block/updated-at
:block/file
:block/heading-level
{:block/page
[:db/id :block/name :block/original-name :block/journal-day :block/journal?]}])
:where
[?block :block/page ?page]
[?page :block/journal? true]
[?block :block/marker ?marker]
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]
[(missing? $ ?block :block/scheduled)]
[(missing? $ ?block :block/deadline)]]
`,
scheduleStart: 'page.journal-day',
dateFormatter: 'YYYYMMDD',
},
// milestone
{
script: `
[:find (pull ?block [*])
:where
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[?rp :block/name "milestone"]
[?block :block/refs ?rp]]
[:find (pull ?block [*])
:where
[?page :block/name ?pname]
[?block :block/page ?page]
(not [(contains? #{"高中教务系统"} ?pname)])
[?rp :block/name "milestone"]
[?block :block/refs ?rp]]
`,
scheduleStart: 'scheduled',
dateFormatter: 'YYYYMMDD',
Expand Down
Loading

0 comments on commit 83c64c5

Please sign in to comment.