adds option to disable comments

This commit is contained in:
latenitecoding 2024-01-27 20:29:27 -06:00
parent f61649c0f1
commit 38e11cc131
3 changed files with 31 additions and 12 deletions

View file

@ -71,6 +71,7 @@ Here are the available settings for a `chessStudy` code block:
| `chessStudyId` | Valid nanoid | Valid ID for a file stored in the plugin storage |
| `boardOrientation` | `white` \| `black` | Orientation of the board |
| `boardColor` | `green` \| `brown` | Color of the board |
| `viewComments` | `true` \| `false` | Whether to display the comments section |
You can permanently set some settings in the [Obsidian](https://obsidian.md/) plugin settings for Obsidian Chess Study.

View file

@ -4,11 +4,13 @@ import ChessStudyPlugin from 'src/main';
export interface ChessStudyPluginSettings {
boardOrientation: 'white' | 'black';
boardColor: 'green' | 'brown';
viewComments: true | false;
}
export const DEFAULT_SETTINGS: ChessStudyPluginSettings = {
boardOrientation: 'white',
boardColor: 'green',
viewComments: true,
};
export class SettingsTab extends PluginSettingTab {
@ -55,5 +57,21 @@ export class SettingsTab extends PluginSettingTab {
this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('View Comments')
.setDesc('Sets the default view of the comments')
.addDropdown((dropdown) => {
dropdown.addOption('true', 'True');
dropdown.addOption('false', 'False');
dropdown
.setValue(this.plugin.settings.viewComments)
.onChange((viewComments) => {
this.plugin.settings.viewComments = (viewComments == true || viewComments == "true" || viewComments == "True") as true | false;
this.plugin.saveSettings();
});
});
}
}

View file

@ -55,10 +55,8 @@ export const ChessStudy = ({
dataAdapter,
}: AppProps) => {
// Parse Obsidian / Code Block Settings
const { boardColor, boardOrientation, chessStudyId } = parseUserConfig(
pluginSettings,
source
);
const { boardColor, boardOrientation, viewComments, chessStudyId } =
parseUserConfig(pluginSettings, source);
// Setup Chessground API
const [chessView, setChessView] = useState<Api | null>(null);
@ -276,14 +274,16 @@ export const ChessStudy = ({
/>
</div>
</div>
<div className="CommentSection">
<CommentSection
currentComment={gameState.currentMove?.comment}
setComments={(comment: JSONContent) =>
dispatch({ type: 'SYNC_COMMENT', comment: comment })
}
/>
</div>
{viewComments && (
<div className="CommentSection">
<CommentSection
currentComment={gameState.currentMove?.comment}
setComments={(comment: JSONContent) =>
dispatch({ type: 'SYNC_COMMENT', comment: comment })
}
/>
</div>
)}
</div>
);
};