Skip to content

Commit

Permalink
Config setting to use boolean instead of string
Browse files Browse the repository at this point in the history
Signed-off-by: Azri Adam <[email protected]>
  • Loading branch information
azri-cs committed Oct 31, 2024
1 parent da5f0c5 commit 25243ee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SettingsController extends Controller
{
public const ACCEPTED_KEYS = [
'workspace_enabled',
'user_text_editor_max_width'
'is_full_width_editor'
];

public function __construct(
Expand All @@ -34,7 +34,7 @@ public function __construct(
/**
* @throws \OCP\PreConditionNotMetException
*
* @psalm-return DataResponse<200|400, array{workspace_enabled?: mixed, user_text_editor_max_width?: mixed, message?: 'Invalid config key'}, array<never, never>>
* @psalm-return DataResponse<200|400, array{workspace_enabled?: mixed, is_full_width_editor?: mixed, message?: 'Invalid config key'}, array<never, never>>
*/
#[NoAdminRequired]
public function updateConfig(string $key, int|string $value): DataResponse
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function isNotifyPushSyncEnabled(): bool

}

public function getUserPreferencesTextEditorMaxWidth(?string $userId): string
public function isFullWidthEditor(?string $userId): bool
{
return $this->config->getUserValue($userId, Application::APP_NAME, 'user_text_editor_max_width', '80ch');
return $this->config->getUserValue($userId, Application::APP_NAME, 'is_full_width_editor', '0') === '1';
}
}
4 changes: 2 additions & 2 deletions lib/Service/InitialStateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public function provideState(): void
);

$this->initialState->provideInitialState(
'user_text_editor_max_width',
$this->configService->getUserPreferencesTextEditorMaxWidth($this->userId),
'is_full_width_editor',
$this->configService->isFullWidthEditor($this->userId),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export default {
}
},
editorMaxWidth() {
return loadState('text', 'user_text_editor_max_width', '80ch')
return loadState('text', 'is_full_width_editor', false) ? '100%' : '80ch'
},
},
watch: {
Expand Down
14 changes: 5 additions & 9 deletions src/components/Editor/SessionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ export default {
},
},
data() {
const savedWidth = loadState('text', 'user_text_editor_max_width', '80ch')
const isFullWidth = loadState('text', 'is_full_width_editor', false)
return {
myName: '',
user_text_editor_max_width: savedWidth,
isFullWidth: savedWidth === '100%',
isFullWidth,
}
},
computed: {
Expand Down Expand Up @@ -112,15 +111,12 @@ export default {
},
methods: {
onWidthToggle(checked) {
const newWidth = checked ? '100%' : '80ch'
this.user_text_editor_max_width = newWidth
this.isFullWidth = checked
this.$emit('editor-width-change', newWidth)
this.$emit('editor-width-change', checked ? '100%' : '80ch')

Check warning on line 115 in src/components/Editor/SessionList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/SessionList.vue#L57-L115

Added lines #L57 - L115 were not covered by tests
axios.post(generateUrl('/apps/text/settings'), {
key: 'user_text_editor_max_width',
value: newWidth,
key: 'is_full_width_editor',
value: checked ? '1' : '0',
})
},
},
Expand Down

0 comments on commit 25243ee

Please sign in to comment.