Merge pull request #1 from SuperChamp234/settings-sync
Working settings Sync, user can just add their API keys and userIDs in the settings tab for the plugin
This commit is contained in:
commit
0e6751f093
11 changed files with 127 additions and 26 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
|
@ -14,4 +14,11 @@ main.js
|
||||||
data.json
|
data.json
|
||||||
|
|
||||||
#vscode
|
#vscode
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
#buildfiles
|
||||||
|
settings.js
|
||||||
|
view/App.js
|
||||||
|
ReactView.js
|
||||||
|
settings.js
|
||||||
|
view.js
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import App from "./view/App";
|
import App from "./view/App";
|
||||||
|
|
||||||
export const ReactView = () => {
|
export default function ReactView(props: any){
|
||||||
return <App />;
|
return(
|
||||||
};
|
<App username={props.userID} apiToken={props.tokenAPI}/>
|
||||||
|
)
|
||||||
|
}
|
||||||
8
main.ts
8
main.ts
|
|
@ -4,9 +4,13 @@ import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view"
|
||||||
|
|
||||||
interface ExamplePluginSettings {
|
interface ExamplePluginSettings {
|
||||||
dateFormat: string
|
dateFormat: string
|
||||||
|
userID: string
|
||||||
|
apiToken: string
|
||||||
}
|
}
|
||||||
const DEFAULT_SETTINGS: Partial<ExamplePluginSettings> = {
|
const DEFAULT_SETTINGS: Partial<ExamplePluginSettings> = {
|
||||||
dateFormat: "YYYY-MM-DD"
|
dateFormat: "YYYY-MM-DD",
|
||||||
|
userID: "",
|
||||||
|
apiToken: ""
|
||||||
}
|
}
|
||||||
export default class ExamplePlugin extends Plugin {
|
export default class ExamplePlugin extends Plugin {
|
||||||
settings: ExamplePluginSettings;
|
settings: ExamplePluginSettings;
|
||||||
|
|
@ -17,7 +21,7 @@ export default class ExamplePlugin extends Plugin {
|
||||||
this.addSettingTab(new ExampleSettingsTab(this.app, this));
|
this.addSettingTab(new ExampleSettingsTab(this.app, this));
|
||||||
this.registerView(
|
this.registerView(
|
||||||
VIEW_TYPE_EXAMPLE,
|
VIEW_TYPE_EXAMPLE,
|
||||||
(leaf) => (this.view = new ExampleView(leaf))
|
(leaf) => (this.view = new ExampleView(leaf, this))
|
||||||
);
|
);
|
||||||
this.addRibbonIcon("dice", "Activate view", () => { //activate view
|
this.addRibbonIcon("dice", "Activate view", () => { //activate view
|
||||||
this.activateView();
|
this.activateView();
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
import { ItemView,WorkspaceLeaf } from "obsidian";
|
import { ItemView,WorkspaceLeaf } from "obsidian";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
import { ReactView } from "./ReactView";
|
import ReactView from "./ReactView";
|
||||||
|
import ExamplePlugin from "main";
|
||||||
|
|
||||||
|
|
||||||
export const VIEW_TYPE_EXAMPLE = "example-view"
|
export const VIEW_TYPE_EXAMPLE = "example-view"
|
||||||
|
|
||||||
export class ExampleView extends ItemView {
|
export class ExampleView extends ItemView {
|
||||||
|
plugin: ExamplePlugin;
|
||||||
constructor(leaf: WorkspaceLeaf) {
|
constructor(leaf: WorkspaceLeaf) {
|
||||||
super(leaf)
|
super(leaf)
|
||||||
}
|
}
|
||||||
|
|
@ -17,8 +17,11 @@
|
||||||
"@types/node": "^14.14.37",
|
"@types/node": "^14.14.37",
|
||||||
"@types/react": "^17.0.27",
|
"@types/react": "^17.0.27",
|
||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
|
"css-loader": "^6.4.0",
|
||||||
|
"extract-text-webpack-plugin": "^2.1.2",
|
||||||
"obsidian": "^0.12.0",
|
"obsidian": "^0.12.0",
|
||||||
"rollup": "^2.32.1",
|
"rollup": "^2.32.1",
|
||||||
|
"style-loader": "^3.3.0",
|
||||||
"tslib": "^2.2.0",
|
"tslib": "^2.2.0",
|
||||||
"typescript": "^4.2.4"
|
"typescript": "^4.2.4"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
38
settings.ts
38
settings.ts
|
|
@ -12,19 +12,31 @@ export class ExampleSettingsTab extends PluginSettingTab {
|
||||||
display(): void {
|
display(): void {
|
||||||
let { containerEl } = this;
|
let { containerEl } = this;
|
||||||
containerEl.empty();
|
containerEl.empty();
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName("Date format")
|
.setName("Habitica User ID")
|
||||||
.setDesc("Default date format")
|
.setDesc("Can be found in Settings > API")
|
||||||
.addText((text) =>
|
.addText((text) =>
|
||||||
|
text
|
||||||
text
|
.setPlaceholder("User ID")
|
||||||
.setPlaceholder("MMMM dd, yyyy")
|
.setValue(this.plugin.settings.userID)
|
||||||
.setValue(this.plugin.settings.dateFormat)
|
.onChange(async (value) => {
|
||||||
.onChange(async (value) => {
|
this.plugin.settings.userID = value;
|
||||||
this.plugin.settings.dateFormat = value;
|
await this.plugin.saveSettings();
|
||||||
await this.plugin.saveSettings();
|
})
|
||||||
})
|
);
|
||||||
);
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName("Habitica API Token")
|
||||||
|
.setDesc("Can be found in Settings > API")
|
||||||
|
.addText((text) =>
|
||||||
|
text
|
||||||
|
.setPlaceholder("API Token")
|
||||||
|
.setValue(this.plugin.settings.apiToken)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.apiToken = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
23
styles.css
23
styles.css
|
|
@ -11,4 +11,25 @@
|
||||||
|
|
||||||
.book__author {
|
.book__author {
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.todo-item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0px 0px 0;
|
||||||
|
width: 80%;
|
||||||
|
border-bottom: 1px solid #cecece;
|
||||||
|
font-family: Roboto, sans-serif;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=checkbox] {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=checkbox]:focus {
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
|
@ -19,5 +19,5 @@
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"**/*.ts"
|
"**/*.ts"
|
||||||
]
|
, "view/TodoItem.tsx" ]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
view.tsx
Normal file
35
view.tsx
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { ItemView,WorkspaceLeaf } from "obsidian";
|
||||||
|
import * as React from "react";
|
||||||
|
import * as ReactDOM from "react-dom";
|
||||||
|
import ReactView from "./ReactView";
|
||||||
|
import ExamplePlugin from "main";
|
||||||
|
|
||||||
|
|
||||||
|
export const VIEW_TYPE_EXAMPLE = "example-view"
|
||||||
|
|
||||||
|
export class ExampleView extends ItemView {
|
||||||
|
plugin: ExamplePlugin;
|
||||||
|
constructor(leaf: WorkspaceLeaf, plugin: ExamplePlugin) {
|
||||||
|
super(leaf)
|
||||||
|
this.plugin = plugin
|
||||||
|
}
|
||||||
|
|
||||||
|
getViewType() {
|
||||||
|
return VIEW_TYPE_EXAMPLE
|
||||||
|
}
|
||||||
|
|
||||||
|
getDisplayText() {
|
||||||
|
return "Example View"
|
||||||
|
}
|
||||||
|
|
||||||
|
async onOpen() {
|
||||||
|
ReactDOM.render(
|
||||||
|
<ReactView userID = {this.plugin.settings.userID} tokenAPI = {this.plugin.settings.apiToken}/>,
|
||||||
|
this.containerEl.children[1]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async onClose(){
|
||||||
|
ReactDOM.unmountComponentAtNode(this.containerEl.children[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
view/App.tsx
11
view/App.tsx
|
|
@ -1,12 +1,15 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { getTasks } from "./habiticaAPI"
|
import { getTasks } from "./habiticaAPI"
|
||||||
|
import TodoItem from "./TodoItem"
|
||||||
|
|
||||||
const username = "<key>"
|
let username = ""
|
||||||
const credentials = "<key>"
|
let credentials = ""
|
||||||
|
|
||||||
class App extends React.Component<any,any> {
|
class App extends React.Component<any,any> {
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
super(props)
|
super(props)
|
||||||
|
username = this.props.username
|
||||||
|
credentials = this.props.apiToken
|
||||||
this.state = {
|
this.state = {
|
||||||
isLoaded: false,
|
isLoaded: false,
|
||||||
tasks: ""
|
tasks: ""
|
||||||
|
|
@ -17,7 +20,6 @@ class App extends React.Component<any,any> {
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(
|
.then(
|
||||||
result => {
|
result => {
|
||||||
console.log(result.data)
|
|
||||||
this.setState({
|
this.setState({
|
||||||
isLoaded: true,
|
isLoaded: true,
|
||||||
tasks: result.data
|
tasks: result.data
|
||||||
|
|
@ -40,7 +42,8 @@ class App extends React.Component<any,any> {
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
} else {
|
} else {
|
||||||
const listItems = tasks.map((tasks: any) =>
|
const listItems = tasks.map((tasks: any) =>
|
||||||
<li>{tasks.text}</li>
|
<TodoItem key={tasks.id} task={tasks}/>
|
||||||
|
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<ul>{listItems}</ul>
|
<ul>{listItems}</ul>
|
||||||
|
|
|
||||||
12
view/TodoItem.tsx
Normal file
12
view/TodoItem.tsx
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
function TodoItem(props: any) {
|
||||||
|
return (
|
||||||
|
<div className="todo-item">
|
||||||
|
<input type="checkbox" />
|
||||||
|
<p>{props.task.text}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TodoItem
|
||||||
Loading…
Add table
Add a link
Reference in a new issue