Add reading estimate

This commit is contained in:
Bojan Mojsilovic 2024-05-31 16:09:37 +02:00
parent b4b51a242d
commit 254499a4e4
3 changed files with 23 additions and 1 deletions

View File

@ -152,6 +152,13 @@
font-weight: 700; font-weight: 700;
line-height: 24px; line-height: 24px;
} }
.estimate {
color: var(--text-tertiary);
font-size: 15px;
font-weight: 400;
line-height: 24px;
}
} }
} }
.image { .image {

View File

@ -44,6 +44,9 @@ const ArticlePreview: Component<{
<div class={styles.title}> <div class={styles.title}>
{props.article.title} {props.article.title}
</div> </div>
<div class={styles.estimate}>
{Math.ceil(props.article.wordCount / 238)} minutes
</div>
</div> </div>
</div> </div>
<Show when={props.article.image.length > 0}> <Show when={props.article.image.length > 0}>

View File

@ -196,6 +196,7 @@ export const fetchArticles = (pubkey: string | undefined, noteIds: string[], sub
topZaps: {}, topZaps: {},
since: 0, since: 0,
until: 0, until: 0,
wordCount: {},
} }
const events = noteIds.reduce<EventCoordinate[]>((acc, id) => { const events = noteIds.reduce<EventCoordinate[]>((acc, id) => {
@ -231,7 +232,6 @@ export const fetchArticles = (pubkey: string | undefined, noteIds: string[], sub
}); });
getParametrizedEvents(events, subId); getParametrizedEvents(events, subId);
// getEvents(pubkey, [...noteIds], subId, true);
const updatePage = (content: NostrEventContent) => { const updatePage = (content: NostrEventContent) => {
if (content.kind === Kind.Metadata) { if (content.kind === Kind.Metadata) {
@ -358,6 +358,17 @@ export const fetchArticles = (pubkey: string | undefined, noteIds: string[], sub
return; return;
} }
if (content.kind === Kind.WordCount) {
const count = JSON.parse(content.content) as { event_id: string, words: number };
if (!page.wordCount) {
page.wordCount = {};
}
page.wordCount[count.event_id] = count.words
return;
}
if (content.kind === Kind.NoteQuoteStats) { if (content.kind === Kind.NoteQuoteStats) {
const quoteStats = JSON.parse(content.content); const quoteStats = JSON.parse(content.content);
@ -384,6 +395,7 @@ export const fetchArticleThread = (pubkey: string | undefined, noteIds: string,
topZaps: {}, topZaps: {},
since: 0, since: 0,
until: 0, until: 0,
wordCount: {},
} }
let primaryArticle: PrimalArticle | undefined; let primaryArticle: PrimalArticle | undefined;