added chapter view, fixes, added ratings, added chapter updates/deletions
This commit is contained in:
parent
029b7e9353
commit
4801cf3a13
34 changed files with 1345 additions and 191 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { RatingType as RatingTypeSchema } from '@generated/types';
|
||||
import { Descendant, Text } from 'slate';
|
||||
import { IdentityContext } from './identity';
|
||||
|
||||
export function ensureIdentity(
|
||||
|
|
@ -5,3 +7,28 @@ export function ensureIdentity(
|
|||
): asserts identity is NonNullable<IdentityContext['identity']> {
|
||||
if (identity == null) throw new Error('Unauthorized.');
|
||||
}
|
||||
|
||||
export function countWords(descendants: Descendant[]): number {
|
||||
let wordCount = 0;
|
||||
|
||||
function traverse(nodes: Descendant[]) {
|
||||
for (const node of nodes) {
|
||||
if (Text.isText(node)) {
|
||||
const words = node.text.trim().split(/\s+/).filter(Boolean);
|
||||
wordCount += words.length;
|
||||
} else if ('children' in node) {
|
||||
traverse(node.children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
traverse(descendants);
|
||||
return wordCount;
|
||||
}
|
||||
|
||||
export function ensureRatingType(value: string): asserts value is RatingTypeSchema {
|
||||
if (value === RatingTypeSchema.Up) return;
|
||||
if (value === RatingTypeSchema.Down) return;
|
||||
|
||||
throw new Error('Invalid rating type');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue