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;
line-height: 24px;
}
.estimate {
color: var(--text-tertiary);
font-size: 15px;
font-weight: 400;
line-height: 24px;
}
}
}
.image {

View File

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

View File

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