Skip to content

Commit

Permalink
refactor: free up the CardOption name in supportedOptions
Browse files Browse the repository at this point in the history
It will be used to replace classes of the Settings.
  • Loading branch information
aalemayhu committed Dec 24, 2024
1 parent 2c67b4d commit 5ab9fbf
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 109 deletions.
21 changes: 21 additions & 0 deletions src/controllers/CardOptionsController/CardOptionDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export class CardOptionDetail {
key: string;

label: string;

value: boolean;

description: string;

constructor(
key: string,
label: string,
description: string,
defaultValue: boolean
) {
this.key = key;
this.label = label;
this.description = description;
this.value = defaultValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Request, Response } from 'express';
import { sendError } from '../../lib/error/sendError';
import { IServiceSettings } from '../../services/SettingsService';
import { getOwner } from '../../lib/User/getOwner';
import supportedOptions, { CardOption } from './supportedOptions';
import Settings from '../../lib/parser/Settings';
import supportedOptions from './supportedOptions';
import CardOption from '../../lib/parser/Settings/CardOption';

class CardOptionsController {
constructor(private readonly service: IServiceSettings) {}
Expand Down Expand Up @@ -66,7 +66,7 @@ class CardOptionsController {
return { ...accumulator, ...current };
}, {});
}
return Settings.LoadDefaultOptions();
return CardOption.LoadDefaultOptions();
}

getDefaultOptions() {
Expand Down
62 changes: 21 additions & 41 deletions src/controllers/CardOptionsController/supportedOptions.ts
Original file line number Diff line number Diff line change
@@ -1,136 +1,116 @@
export class CardOption {
key: string;
import { CardOptionDetail } from './CardOptionDetail';

label: string;

value: boolean;

description: string;

constructor(
key: string,
label: string,
description: string,
defaultValue: boolean
) {
this.key = key;
this.label = label;
this.description = description;
this.value = defaultValue;
}
}

const supportedOptions = (): CardOption[] => {
const supportedOptions = (): CardOptionDetail[] => {
const v = [
new CardOption(
new CardOptionDetail(
'add-notion-link',
'Add Notion Link',
'Add a link to the Notion page where the toggle was created. Please use this with the (Use Notion ID) to avoid duplicates.',
false
),
new CardOption(
new CardOptionDetail(
'use-notion-id',
'Use Notion ID',
'By default we create a new id from your fields. This can cause duplicates and in those cases you want to enable the Notion ID which is more reliable and avoid duplicates.',
true
),
new CardOption(
new CardOptionDetail(
'all',
'Use All Toggle Lists',
'By default we only check for toggle lists in the first page. Use this option to retreive toggle lists from anywhere in the page.',
true
),
new CardOption(
new CardOptionDetail(
'paragraph',
'Use Plain Text for Back',
'This option will remove formatting and get the text content only.',
false
),
new CardOption(
new CardOptionDetail(
'cherry',
'Enable Cherry Picking Using 🍒 Emoji',
'This will Only create flashcards from the toggle lists that include 🍒 in the toggle (header or body)',
false
),
new CardOption(
new CardOptionDetail(
'avocado',
"Only Create Flashcards From Toggles That Don't Have The 🥑 Emoji",
"This option enables you to ignore certain toggles when creating flashcards from pages that you don't want to change too much.",
false
),
new CardOption(
new CardOptionDetail(
'tags',
'Treat Strikethrough as Tags',
'This will go treat the strikethroughs in the page as global ones. The ones inside of a toggle will be treated as locally to the toggle.',
false
),
new CardOption(
new CardOptionDetail(
'cloze',
'Cloze Deletion',
'Create cloze flashcards from code blocks.',
true
),
new CardOption(
new CardOptionDetail(
'enable-input',
'Treat Bold Text as Input',
'Words marked as bold will be removed and you will have to enter them in when reviewing the card. This is useful when you need to type out the answer.',
false
),
new CardOption(
new CardOptionDetail(
'basic-reversed',
'Basic and Reversed',
'Create the question and answer flashcards but also reversed ones. Where the answer and question change places.',
false
),
new CardOption(
new CardOptionDetail(
'reversed',
'Just the Reversed Flashcards',
'Only create flashcards from the reverse. This is useful when you want to say show an image first.',
false
),
new CardOption(
new CardOptionDetail(
'no-underline',
'Remove Underlines',
'Disable underline. This is an option that was created due to changes in the way Notion handles underlines.',
false
),
new CardOption(
new CardOptionDetail(
'max-one-toggle-per-card',
'Maximum One Toggle Per Card',
"This will limit to 1 card so you don't see too many toggles in one card. When you combine this with 'Use all toggle lists' you can create flashcards from everything in your upload, regardless of how deeply nested they are.",
true
),
new CardOption(
new CardOptionDetail(
'remove-mp3-links',
'Remove the MP3 Links Created From Audio Files',
"Due to backwards-compatability we leave links untouched but this option let's you remove mp3 links",
true
),
new CardOption(
new CardOptionDetail(
'perserve-newlines',
'Preserve Newlines in the Toggle Header and Body',
'This will allow you to use SHIFT-Enter in the toggles to create multiple lines for all card types (Basic, Cloze, etc.)',
true
),
new CardOption(
new CardOptionDetail(
'markdown-nested-bullet-points',
'Markdown Nested Bullet Points',
'Enable conversion of bullet and sub bullet points in Markdown. If you are a Obsidian user, enable this',
false
),
new CardOption(
new CardOptionDetail(
'vertex-ai-pdf-questions',
'Generate Questions from Single PDF File Uploads',
'Use Vertex AI API to generate questions from PDFs. This is a paid feature and if enabled will send your notes to Google Cloud.',
false
),
new CardOption(
new CardOptionDetail(
'disable-indented-bullets',
'Disable Indented Bullets',
'Disable indented bullets from becoming separate cards. This applies to bullet lists.',
false
),
new CardOption(
new CardOptionDetail(
'image-quiz-html-to-anki',
'Convert Image Quiz HTML to Anki Cards',
'Use OCR to extract images and answers from HTML quizzes and convert them into Anki flashcards for review. This is a premium experimental feature.',
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/NotionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response } from 'express';

import { sendError } from '../lib/error/sendError';
import performConversion from '../lib/storage/jobs/helpers/performConversion';
import Settings from '../lib/parser/Settings';
import CardOption from '../lib/parser/Settings';
import BlockHandler from '../services/NotionService/BlockHandler/BlockHandler';
import CustomExporter from '../lib/parser/exporters/CustomExporter';
import { BlockObjectResponse } from '@notionhq/client/build/src/api-endpoints';
Expand Down Expand Up @@ -149,7 +149,7 @@ class NotionController {
const api = await this.service.getNotionAPI(res.locals.owner);
const blockId = getNotionId(query) ?? query;
const block = await api.getBlock(blockId);
const settings = new Settings(Settings.LoadDefaultOptions());
const settings = new CardOption(CardOption.LoadDefaultOptions());
let handler = new BlockHandler(
new CustomExporter('x', new Workspace(true, 'fs').location),
api,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/parser/Deck.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Note from './Note';
import Settings from './Settings';
import CardOption from './Settings';

export default class Deck {
name: string;
Expand All @@ -12,7 +12,7 @@ export default class Deck {

id: number;

settings: Settings | null;
settings: CardOption | null;

get cardCount() {
return this.cards.length;
Expand All @@ -24,7 +24,7 @@ export default class Deck {
image: string | undefined,
style: string | null,
id: number,
settings: Settings
settings: CardOption
) {
this.settings = settings;
this.name = name;
Expand Down
18 changes: 9 additions & 9 deletions src/lib/parser/DeckParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { setupTests } from '../../test/configure-jest';
import { getDeck } from '../../test/test-utils';
import Settings from './Settings/';
import CardOption from './Settings/CardOption';

beforeEach(() => setupTests());

test('Toggle Headings', async () => {
const deck = await getDeck(
'Toggle Hea 0e02b 2.html',
new Settings({ cherry: 'false' })
new CardOption({ cherry: 'false' })
);
expect(deck.cards.length).toBeGreaterThan(0);
});

test('Grouped cloze deletions', async () => {
const deck = await getDeck(
'Grouped Cloze Deletions fbf856ad7911423dbef0bfd3e3c5ce5c 3.html',
new Settings({ cherry: 'false', cloze: 'true', reversed: 'true', 'basic-reversed': 'true' })
new CardOption({ cherry: 'false', cloze: 'true', reversed: 'true', 'basic-reversed': 'true' })
);
expect(deck.name).toBe('Grouped Cloze Deletions');
expect(deck.cards.length).toBe(20);
Expand All @@ -24,7 +24,7 @@ test('Grouped cloze deletions', async () => {
test('Cloze Deletions', async () => {
const deck = await getDeck(
'Some Cloze Deletions 1a118169ada841a99a9aaccc7eaa6775.html',
new Settings({ cherry: 'false', reversed: 'true', 'basic-reversed': 'true' })
new CardOption({ cherry: 'false', reversed: 'true', 'basic-reversed': 'true' })
);
expect(deck.cards[0].back).toBe(
"<div class='toggle'>{{c2::Canberra}} was founded in {{c1::1913}}.</div>"
Expand All @@ -49,7 +49,7 @@ test('Cloze Deletions', async () => {
test('Colours', async () => {
const deck = await getDeck(
'Colours 0519bf7e86d84ee4ba710c1b7ff7438e.html',
new Settings({ cherry: 'false' })
new CardOption({ cherry: 'false' })
);
expect(deck.cards[0].back.includes('block-color')).toBe(true);
});
Expand All @@ -63,15 +63,15 @@ test.skip('HTML Regression Test', (t) => {
test('Nested Toggles', async () => {
const deck = await getDeck(
'Nested Toggles.html',
new Settings({ cherry: 'true', reversed: 'true', 'basic-reversed': 'true' })
new CardOption({ cherry: 'true', reversed: 'true', 'basic-reversed': 'true' })
);
expect(deck.cards.length).toBe(12);
});

test('Global Tags', async () => {
const deck = await getDeck(
'Global Tag Support.html',
new Settings({ tags: 'true', cherry: 'false' })
new CardOption({ tags: 'true', cherry: 'false' })
);
// use toContain
expect(deck.cards[0].tags.includes('global')).toBe(true);
Expand All @@ -82,15 +82,15 @@ test.todo('Multiple File Uploads');
test.todo('Test Basic Card');

test('Markdown empty deck', async () => {
const deck = await getDeck('empty-deck.md', new Settings({
const deck = await getDeck('empty-deck.md', new CardOption({
"markdown-nested-bullet-points": "true"
}));
expect(deck.name).toBe('Empty Deck');
expect(deck.cards.length).toBe(0);
})

test('Markdown nested bullet points', async () => {
const deck = await getDeck('simple-deck.md', new Settings({
const deck = await getDeck('simple-deck.md', new CardOption({
"markdown-nested-bullet-points": "true",
"reversed": "false",
"basic-reversed": "false",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/parser/DeckParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sanitizeTags from '../anki/sanitizeTags';
import { File } from '../zip/zip';
import Deck from './Deck';
import Note from './Note';
import Settings from './Settings';
import CardOption from './Settings';
import Workspace from './WorkSpace';
import CustomExporter from './exporters/CustomExporter';
import handleClozeDeletions from './helpers/handleClozeDeletions';
Expand Down Expand Up @@ -35,7 +35,7 @@ import { NO_PACKAGE_ERROR } from '../error/constants';

export interface DeckParserInput {
name: string;
settings: Settings;
settings: CardOption;
files: File[];
noLimits: boolean;
workspace: Workspace;
Expand All @@ -46,7 +46,7 @@ export class DeckParser {

firstDeckName: string;

settings: Settings;
settings: CardOption;

payload: Deck[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parseTemplate } from './helpers/parseTemplate';
import { UserSuppliedTemplateFile } from './types';
import { sendError } from '../../error/sendError';

export class Settings {
class CardOption {
readonly deckName: string | undefined;

readonly useInput: boolean;
Expand Down Expand Up @@ -150,3 +150,5 @@ export class Settings {
};
}
}

export default CardOption;
4 changes: 2 additions & 2 deletions src/lib/parser/Settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Settings } from './Settings';
import { CardOption } from './CardOption';

Check failure on line 1 in src/lib/parser/Settings/index.ts

View workflow job for this annotation

GitHub Actions / build (20.18.0)

Module '"./CardOption"' has no exported member 'CardOption'. Did you mean to use 'import CardOption from "./CardOption"' instead?

export default Settings;
export default CardOption;
Loading

0 comments on commit 5ab9fbf

Please sign in to comment.