Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar collection view #369

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4660dc7
WIP: Calendar view basis
MichaelCasaDev Sep 8, 2022
049bf1a
Update collection-view-calendar.tsx
MichaelCasaDev Sep 8, 2022
5347db8
Update collection-view-calendar.tsx
MichaelCasaDev Sep 9, 2022
d761e42
Calendar controls
MichaelCasaDev Sep 9, 2022
4d1bb6f
Hide calendar controls
MichaelCasaDev Sep 9, 2022
a858ae5
Moved style to CSS
MichaelCasaDev Sep 9, 2022
55a9051
Added dark-mode css
MichaelCasaDev Sep 11, 2022
2d89f18
Fix today box CSS
MichaelCasaDev Sep 11, 2022
f0ffd87
Update styles.css
MichaelCasaDev Sep 11, 2022
d129da0
Update collection-view-calendar.tsx
MichaelCasaDev Sep 11, 2022
9cdb9c5
Update styles.css
MichaelCasaDev Sep 13, 2022
5045948
Update collection-view-calendar.tsx
MichaelCasaDev Sep 20, 2022
4bd0b11
Now can start weeks on monday
MichaelCasaDev Sep 23, 2022
78e122f
Update readme.md
MichaelCasaDev Sep 23, 2022
a8d0be2
Merge branch 'master' into collection-view-calendar
MichaelCasaDev Oct 17, 2022
91e6118
Lot of fixes
MichaelCasaDev Feb 3, 2023
b8d6cea
More styling
MichaelCasaDev Feb 3, 2023
d156bef
Send it!
MichaelCasaDev Feb 3, 2023
bbec671
Run Eslint and Prettier
MichaelCasaDev Feb 3, 2023
440c985
Fix today date indicator
MichaelCasaDev Feb 6, 2023
4ad45dc
Comments and minor fixes
MichaelCasaDev Oct 1, 2023
0f9858d
Update readme.md
MichaelCasaDev Oct 1, 2023
1e6d33b
Merge branch 'master' into collection-view-calendar
MichaelCasaDev Oct 1, 2023
e6e62b6
Fix for PR checks
MichaelCasaDev Oct 1, 2023
d899d24
Merge branch 'NotionX:master' into collection-view-calendar
MichaelCasaDev Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/notion-types/src/collection-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export interface BoardCollectionView extends BaseCollectionView {

export interface CalendarCollectionView extends BaseCollectionView {
type: 'calendar'

// TODO
visible: boolean
property?: PropertyID
}

export type CollectionView =
Expand Down
89 changes: 89 additions & 0 deletions packages/notion-utils/src/get-page-property-from-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Block, DateFormat, ExtendedRecordMap } from 'notion-types'

import { getTextContent } from './get-text-content'

/**
* Gets the value of a collection property for a given page (collection item).
*
* @param propertyId property id
* @param block Page block, often be first block in blockMap
* @param recordMap
* @returns - The return value types will follow the following principles:
* 1. if property is date type, it will return `number` or `number[]`(depends on `End Date` switch)
* 2. property is text-like will return `string`
* 3. multi select property will return `string[]`
* 4. checkbox property return `boolean`
* @todo complete all no-text property type
*/
export function getPagePropertyFromId<
T = string | number | boolean | string[] | number[]
>(propertyId: string, block: Block, recordMap: ExtendedRecordMap): T
export function getPagePropertyFromId(
propertyId: string,
block: Block,
recordMap: ExtendedRecordMap
) {
try {
if (!block.properties || !Object.keys(recordMap.collection)) {
// console.warn(
// `block ${block.id} has no properties or this recordMap has no collection record`
// )
return null
}

const collection = recordMap.collection[block.parent_id]?.value

if (collection) {
if (!propertyId) {
return null
}

const { type } = collection.schema[propertyId]
const content = getTextContent(block.properties[propertyId])

switch (type) {
case 'created_time':
return block.created_time

case 'multi_select':
return content.split(',')

case 'date': {
const property = block.properties[propertyId] as [['‣', [DateFormat]]]
const formatDate = property[0][1][0][1]

if (formatDate.type == 'datetime') {
return new Date(
`${formatDate.start_date} ${formatDate.start_time}`
).getTime()
} else if (formatDate.type == 'date') {
return new Date(formatDate.start_date).getTime()
} else if (formatDate.type == 'datetimerange') {
const { start_date, start_time, end_date, end_time } = formatDate
const startTime = new Date(`${start_date} ${start_time}`).getTime()
const endTime = new Date(`${end_date} ${end_time}`).getTime()
return [startTime, endTime]
} else {
const startTime = new Date(formatDate.start_date).getTime()
const endTime = new Date(formatDate.end_date).getTime()
return [startTime, endTime]
}
}

case 'checkbox':
return content == 'Yes'

case 'last_edited_time':
return block.last_edited_time

default:
return content
}
}
} catch {
// ensure that no matter what, we don't throw errors because of an unexpected
// collection data format
}

return null
}
1 change: 1 addition & 0 deletions packages/notion-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './get-block-icon'
export * from './get-block-collection-id'
export * from './get-page-title'
export * from './get-page-property'
export * from './get-page-property-from-id'
export * from './get-date-value'
export * from './get-block-parent-page'
export * from './get-page-table-of-contents'
Expand Down
6 changes: 6 additions & 0 deletions packages/react-notion-x/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface NotionContext {
previewImages: boolean
forceCustomImages: boolean
showCollectionViewDropdown: boolean
showCalendarControls: boolean
startWeekOnMonday: boolean
showTableOfContents: boolean
minTableOfContentsItems: number
linkTableTitleProperties: boolean
Expand Down Expand Up @@ -66,6 +68,8 @@ export interface PartialNotionContext {
isLinkCollectionToUrlProperty?: boolean

showTableOfContents?: boolean
showCalendarControls?: boolean
startWeekOnMonday?: boolean
minTableOfContentsItems?: number

defaultPageIcon?: string
Expand Down Expand Up @@ -167,6 +171,8 @@ const defaultNotionContext: NotionContext = {
isLinkCollectionToUrlProperty: false,

showTableOfContents: false,
showCalendarControls: true,
startWeekOnMonday: false,
minTableOfContentsItems: 3,

defaultPageIcon: null,
Expand Down
11 changes: 11 additions & 0 deletions packages/react-notion-x/src/icons/left-chevron.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react'

function SvgLeftChevron(props: React.SVGProps<SVGSVGElement>) {
return (
<svg viewBox='0 0 30 30' {...props}>
<polygon points='12.6 15 23 25.2 20.2 28 7 15 20.2 2 23 4.8'></polygon>
</svg>
)
}

export default SvgLeftChevron
11 changes: 11 additions & 0 deletions packages/react-notion-x/src/icons/right-chevron.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react'

function SvgRightChevron(props: React.SVGProps<SVGSVGElement>) {
return (
<svg viewBox='0 0 30 30' {...props}>
<polygon points='17.4,15 7,25.2 9.8,28 23,15 9.8,2 7,4.8'></polygon>
</svg>
)
}

export default SvgRightChevron
6 changes: 6 additions & 0 deletions packages/react-notion-x/src/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const NotionRenderer: React.FC<{
isImageZoomable?: boolean

showTableOfContents?: boolean
showCalendarControls?: boolean
startWeekOnMonday?: boolean
minTableOfContentsItems?: number

defaultPageIcon?: string
Expand Down Expand Up @@ -77,6 +79,8 @@ export const NotionRenderer: React.FC<{
isLinkCollectionToUrlProperty,
isImageZoomable = true,
showTableOfContents,
showCalendarControls,
startWeekOnMonday,
minTableOfContentsItems,
defaultPageIcon,
defaultPageCover,
Expand Down Expand Up @@ -113,6 +117,8 @@ export const NotionRenderer: React.FC<{
linkTableTitleProperties={linkTableTitleProperties}
isLinkCollectionToUrlProperty={isLinkCollectionToUrlProperty}
showTableOfContents={showTableOfContents}
showCalendarControls={showCalendarControls}
startWeekOnMonday={startWeekOnMonday}
minTableOfContentsItems={minTableOfContentsItems}
defaultPageIcon={defaultPageIcon}
defaultPageCover={defaultPageCover}
Expand Down
Loading
Loading