Skip to content

Commit 66cd353

Browse files
change summary for new vs updated pages
1 parent a13dd25 commit 66cd353

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

components/notion/sources/updated-page/updated-page.mjs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default {
6060
Date.parse(page.last_edited_time),
6161
);
6262
if (count++ < 25) {
63-
this.emitEvent(page, []);
63+
this.emitEvent(page, [], true);
6464
}
6565
}
6666
this._setPropertyValues(propertyValues);
@@ -109,8 +109,10 @@ export default {
109109
ts,
110110
};
111111
},
112-
emitEvent(page, changes) {
113-
const meta = this.generateMeta(page, constants.summaries.PAGE_UPDATED);
112+
emitEvent(page, changes, isNewPage) {
113+
const meta = isNewPage
114+
? this.generateMeta(page, constants.summaries.PAGE_ADDED)
115+
: this.generateMeta(page, constants.summaries.PAGE_UPDATED);
114116
const event = {
115117
page,
116118
changes,
@@ -137,13 +139,18 @@ export default {
137139

138140
for await (const page of pagesStream) {
139141
const changes = [];
142+
let isNewPage = false;
140143
let propertyHasChanged = false;
141144
newLastUpdatedTimestamp = Math.max(
142145
newLastUpdatedTimestamp,
143146
Date.parse(page.last_edited_time),
144147
);
145148

146149
for (const propertyName of propertiesToCheck) {
150+
if (lastCheckedTimestamp > Date.parse(page.last_edited_time)) {
151+
break;
152+
}
153+
147154
const previousValue = structuredClone(propertyValues[page.id]?.[propertyName]);
148155
const currentValue = this.maybeRemoveFileSubItems(page.properties[propertyName]);
149156

@@ -163,6 +170,7 @@ export default {
163170
}
164171

165172
if (!pageExistsInDB && this.includeNewPages) {
173+
isNewPage = true;
166174
propertyHasChanged = true;
167175
propertyValues[page.id] = {
168176
[propertyName]: currentValue,
@@ -174,12 +182,8 @@ export default {
174182
}
175183
}
176184

177-
if (propertyHasChanged && lastCheckedTimestamp <= Date.parse(page.last_edited_time)) {
178-
this.emitEvent(page, changes);
179-
}
180-
181-
if (Date.parse(page.last_edited_time) < lastCheckedTimestamp) {
182-
break;
185+
if (propertyHasChanged) {
186+
this.emitEvent(page, changes, isNewPage);
183187
}
184188
}
185189

0 commit comments

Comments
 (0)