-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatting field switcher + CloudStorage adapter (#8)
- Loading branch information
Showing
24 changed files
with
244 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import sanitizeHtml from "sanitize-html"; | ||
|
||
export const removeAllTags = (text: string) => { | ||
return sanitizeHtml(text); | ||
return sanitizeHtml(text, { | ||
allowedTags: [], | ||
allowedAttributes: {}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import WebApp from "@twa-dev/sdk"; | ||
import { type StorageController } from "mobx-persist-store"; | ||
|
||
// An adapter of the Telegram cloud storage to the mobx-persist-store interface | ||
export const cloudStorageAdapter: StorageController = { | ||
getItem(key: string) { | ||
return new Promise((resolve, reject) => { | ||
WebApp.CloudStorage.getItem(key, (err, value) => { | ||
if (err != null) { | ||
return reject(err); | ||
} else { | ||
// @ts-ignore | ||
return resolve(value); | ||
} | ||
}); | ||
}); | ||
}, | ||
removeItem(key: string) { | ||
return new Promise((resolve, reject) => { | ||
WebApp.CloudStorage.removeItem(key, (err, result) => { | ||
if (err != null) { | ||
return reject(err); | ||
} else { | ||
// @ts-ignore | ||
return resolve(result); | ||
} | ||
}); | ||
}); | ||
}, | ||
setItem(key: string, value: any) { | ||
return new Promise((resolve, reject) => { | ||
WebApp.CloudStorage.setItem(key, value, (err, result) => { | ||
if (err != null) { | ||
return reject(err); | ||
} else { | ||
// @ts-ignore | ||
return resolve(result); | ||
} | ||
}); | ||
}); | ||
}, | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import WebApp from "@twa-dev/sdk"; | ||
import { cloudStorageAdapter } from "./cloud-storage.ts"; | ||
|
||
export const storageAdapter = WebApp.isVersionAtLeast("6.9") | ||
? cloudStorageAdapter | ||
: window.localStorage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { observer } from "mobx-react-lite"; | ||
import { userStore } from "../../store/user-store.ts"; | ||
import { css, cx } from "@emotion/css"; | ||
import { reset } from "../../ui/reset.ts"; | ||
import { theme } from "../../ui/theme.tsx"; | ||
import { ChevronIcon } from "../../ui/chevron-icon.tsx"; | ||
import { t } from "../../translations/t.ts"; | ||
import React from "react"; | ||
|
||
export const FormattingSwitcher = observer(() => { | ||
return ( | ||
<button | ||
onClick={() => { | ||
userStore.isCardFormattingOn.toggle(); | ||
}} | ||
className={cx( | ||
reset.button, | ||
css({ | ||
fontSize: 16, | ||
color: theme.linkColor, | ||
cursor: "pointer", | ||
}), | ||
)} | ||
> | ||
<span | ||
className={css({ | ||
transform: "translateY(2px)", | ||
display: "inline-block", | ||
})} | ||
> | ||
{" "} | ||
<ChevronIcon | ||
direction={userStore.isCardFormattingOn.value ? "top" : "bottom"} | ||
/> | ||
</span>{" "} | ||
{t("formatting")} | ||
</button> | ||
); | ||
}); |
9 changes: 8 additions & 1 deletion
9
...creens/deck-form/store/card-form-store.ts → ...k-form/store/card-form-store-interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { BooleanToggle } from "../../../lib/mobx-form/boolean-toggle.ts"; | ||
import { CardFormType } from "./deck-form-store.ts"; | ||
import { TextField } from "../../../lib/mobx-form/text-field.ts"; | ||
import { DeckSpeakFieldEnum } from "../../../../functions/db/deck/decks-with-cards-schema.ts"; | ||
|
||
export type CardFormStore = { | ||
export type CardFormStoreInterface = { | ||
cardForm?: CardFormType | null; | ||
onSaveCard: () => void; | ||
onBackCard: () => void; | ||
isSaveCardButtonActive: boolean; | ||
isCardPreviewSelected: BooleanToggle; | ||
isSending: boolean; | ||
markCardAsRemoved?: () => void; | ||
|
||
deckForm?: { | ||
speakingCardsLocale: TextField<string | null>; | ||
speakingCardsField: TextField<DeckSpeakFieldEnum | null>; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.