Skip to content

Commit

Permalink
Warning modal
Browse files Browse the repository at this point in the history
  • Loading branch information
kuraysdev committed Mar 31, 2024
1 parent 6e2010d commit 243a938
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/modals/login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { App, ButtonComponent, Modal, Setting } from "obsidian";
import { App, ButtonComponent, Modal, Setting, setIcon, setTooltip } from "obsidian";
import KSyncPlugin from "src/main";
import { WarningModal } from "./warning";

export class LoginModal extends Modal {
private login: string;
Expand Down
24 changes: 24 additions & 0 deletions src/modals/warning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { App, Component, MarkdownRenderer, Modal } from "obsidian";
import KSyncPlugin from "src/main";

export class WarningModal extends Modal {
public plugin: KSyncPlugin;
public text: string;
constructor(app: App, plugin: KSyncPlugin, text: string) {
super(app);

this.plugin = plugin;
this.text = text;
}

async onOpen() {
const { contentEl } = this;
MarkdownRenderer.render(this.app, `# ${this.text}`, contentEl, "", new Component());
}

onClose() {
const { contentEl } = this;

contentEl.empty();
}
}
5 changes: 4 additions & 1 deletion src/services/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import KSyncPlugin from "src/main";
import { WarningModal } from "src/modals/warning";

export class Account {
public plugin: KSyncPlugin;
Expand Down Expand Up @@ -36,11 +37,13 @@ export class Account {
login: email,
password: password
})).data
if(!data) return new WarningModal(this.plugin.app, this.plugin, "Сервер не ответил").open();
if(data.error) return new WarningModal(this.plugin.app, this.plugin, "Неправильный Логин или пароль").open();
this.plugin.settings.token = data.token
this.plugin.saveSettings()

const user = await this.GetData();
this.plugin.logger.info("Используем аккаунт "+user.email)
this.plugin.logger.info(`Входим в аккаунт ${user.email}`)
this.data = user;
}

Expand Down
15 changes: 15 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ If your plugin does not need CSS, delete this file.
border-radius: var(--input-radius);
}

.warning {
width: 100%;
height: fit-content;
border: var(--input-border-width) solid var(--background-modifier-border);
border-radius: var(--input-radius);
background-color: var(--color-red);
padding: 5px;
margin-bottom: 5px;
}

.warning .text {
margin: 15px;
font-size: var(--font-ui-large);
}

.log-list {
list-style-type: none;
padding: 5px;
Expand Down

0 comments on commit 243a938

Please sign in to comment.