Skip to content

Commit

Permalink
feat: added command to update default marker color, marker size and c…
Browse files Browse the repository at this point in the history
…ustom marker URL

refs: #22
  • Loading branch information
aaronczichon committed Oct 27, 2024
1 parent a58ebcf commit 58d7861
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [🚀] Added command support for default map style and API token update
- [🚀] Added command support for default map style, marker color, custom marker URL and API token update

## [Next] - 2024-10-23

Expand Down
28 changes: 28 additions & 0 deletions src/commands/custom-marker.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Notice } from 'obsidian';
import MapboxPlugin from '../main';
import { CustomMarkerUrlModal } from '../modals/custom-marker.modal';

/**
* Creates a modal based on the marker URL modal and opens it.
* Callback function will receive the new set marker URL of the user and saves it to the settings.
* @param plugin instance of the MapboxPlugin (required for getting settings and app instance)
*/
const showModalForCustomMarkerUrl = async (plugin: MapboxPlugin) => {
new CustomMarkerUrlModal(plugin, async (result) => {
plugin.settings.markerUrl = result;
plugin.saveData(plugin.settings);
new Notice('Default marker URL updated. Reload your view.');
}).open();
};

/**
* Used to register a new marker URL command.
* @param plugin instance of the MapboxPlugin
*/
export const changeDefaultMarkerUrlCommand = async (plugin: MapboxPlugin) => {
plugin.addCommand({
id: 'change-default-marker-url',
name: 'Change default marker URL',
callback: () => showModalForCustomMarkerUrl(plugin),
});
};
28 changes: 28 additions & 0 deletions src/commands/map-zoom.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Notice } from 'obsidian';
import MapboxPlugin from '../main';
import { MapZoomModal } from '../modals/map-zoom.modal';

/**
* Creates a modal based on the map zoom and opens it.
* Callback function will receive the new set default map zoom of the user and saves it to the settings.
* @param plugin instance of the MapboxPlugin (required for getting settings and app instance)
*/
const showModalForDefaultMapZoom = async (plugin: MapboxPlugin) => {
new MapZoomModal(plugin, async (result) => {
plugin.settings.mapZoom = result;
plugin.saveData(plugin.settings);
new Notice('Default map zoom level updated. Reload your view.');
}).open();
};

/**
* Used to register a new map zoom command.
* @param plugin instance of the MapboxPlugin
*/
export const changeDefaultMapZoomLevelCommand = async (plugin: MapboxPlugin) => {
plugin.addCommand({
id: 'change-default-map-zoom-level',
name: 'Change default map zoom level',
callback: () => showModalForDefaultMapZoom(plugin),
});
};
28 changes: 28 additions & 0 deletions src/commands/marker-color.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Notice } from 'obsidian';
import MapboxPlugin from '../main';
import { MarkerColorModal } from '../modals/marker-color.modal';

/**
* Creates a modal based on the marker color modal and opens it.
* Callback function will receive the new set marker color of the user and saves it to the settings.
* @param plugin instance of the MapboxPlugin (required for getting settings and app instance)
*/
const showModalForDefaultMarkerColor = async (plugin: MapboxPlugin) => {
new MarkerColorModal(plugin, async (result) => {
plugin.settings.markerColor = result.replace('#', '');
plugin.saveData(plugin.settings);
new Notice('Default marker color updated. Reload your view.');
}).open();
};

/**
* Used to register a new marker color command.
* @param plugin instance of the MapboxPlugin
*/
export const changeDefaultMarkerColorCommand = async (plugin: MapboxPlugin) => {
plugin.addCommand({
id: 'change-default-marker-color',
name: 'Change default marker color',
callback: () => showModalForDefaultMarkerColor(plugin),
});
};
2 changes: 1 addition & 1 deletion src/commands/marker-size.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const showModalForMarkerSize = async (plugin: MapboxPlugin) => {
export const changeMarkerSizeCommand = async (plugin: MapboxPlugin) => {
plugin.addCommand({
id: 'change-marker-size',
name: 'Change marker size',
name: 'Change default marker size',
callback: () => showModalForMarkerSize(plugin),
});
};
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Plugin } from 'obsidian';
import { changeApiTokenCommand } from './commands/api-token.command';
import { changeDefaultMarkerUrlCommand } from './commands/custom-marker.command';
import { changeMapStyleCommand } from './commands/map-style.command';
import { changeDefaultMapZoomLevelCommand } from './commands/map-zoom.command';
import { changeDefaultMarkerColorCommand } from './commands/marker-color.command';
import { changeMarkerSizeCommand } from './commands/marker-size.command';
import { addNewLocationFromClipboard } from './commands/new-from-clipboard.command';
import { toggleReverseCoordinates } from './commands/toggle-reverse.command';
Expand All @@ -23,6 +26,9 @@ export default class MapboxPlugin extends Plugin {
changeMarkerSizeCommand(this);
changeApiTokenCommand(this);
changeMapStyleCommand(this);
changeDefaultMapZoomLevelCommand(this);
changeDefaultMarkerColorCommand(this);
changeDefaultMarkerUrlCommand(this);
toggleReverseCoordinates(this);

// Register the processors for the given code blocks.
Expand Down
23 changes: 23 additions & 0 deletions src/modals/custom-marker.modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Modal, Setting } from 'obsidian';
import MapboxPlugin from '../main';
import { markerUrlSetting } from '../settings/plugin-settings.control';

export class CustomMarkerUrlModal extends Modal {
constructor(plugin: MapboxPlugin, onSubmit: (result: string) => void) {
super(plugin.app);
this.titleEl.setText('Set default custom marker URL');

let markerUrl = plugin.settings.markerUrl;
markerUrlSetting(this.contentEl, plugin, (value: string) => (markerUrl = value));

new Setting(this.contentEl).addButton((btn) =>
btn
.setButtonText('Submit')
.setCta()
.onClick(() => {
this.close();
onSubmit(markerUrl);
}),
);
}
}
23 changes: 23 additions & 0 deletions src/modals/map-zoom.modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Modal, Setting } from 'obsidian';
import MapboxPlugin from '../main';
import { mapZoomSetting } from '../settings/plugin-settings.control';

export class MapZoomModal extends Modal {
constructor(plugin: MapboxPlugin, onSubmit: (result: string) => void) {
super(plugin.app);
this.titleEl.setText('Update default map zoom level');

let zoomLevel = plugin.settings.mapZoom;
mapZoomSetting(this.contentEl, plugin, (value: string) => (zoomLevel = value));

new Setting(this.contentEl).addButton((btn) =>
btn
.setButtonText('Submit')
.setCta()
.onClick(() => {
this.close();
onSubmit(zoomLevel);
}),
);
}
}
23 changes: 23 additions & 0 deletions src/modals/marker-color.modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Modal, Setting } from 'obsidian';
import MapboxPlugin from '../main';
import { markerColorSetting } from '../settings/plugin-settings.control';

export class MarkerColorModal extends Modal {
constructor(plugin: MapboxPlugin, onSubmit: (result: string) => void) {
super(plugin.app);
this.titleEl.setText('Update default marker color');

let color = plugin.settings.markerColor;
markerColorSetting(this.contentEl, plugin, (value: string) => (color = value));

new Setting(this.contentEl).addButton((btn) =>
btn
.setButtonText('Submit')
.setCta()
.onClick(() => {
this.close();
onSubmit(color);
}),
);
}
}
2 changes: 1 addition & 1 deletion src/modals/marker-size.modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { markerSizeSetting } from '../settings/plugin-settings.control';
export class MarkerSizeModal extends Modal {
constructor(plugin: MapboxPlugin, onSubmit: (result: string) => void) {
super(plugin.app);
this.titleEl.setText('Change marker size');
this.titleEl.setText('Change default marker size');

let size: 's' | 'm' | 'l' = plugin.settings.markerSize;
markerSizeSetting(
Expand Down

0 comments on commit 58d7861

Please sign in to comment.