aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates
diff options
context:
space:
mode:
authorwinter2025-01-26 15:25:17 +0000
committerwinter2025-01-26 15:25:17 +0000
commit890dad24d6c095c41e6358b2a6cb61f1b6c2f6ad (patch)
treea662dfd61585b755054075cd93121a9c70a48983 /templates
parent5841d6550936e1fc34f1fbdf4325b1e27ff79230 (diff)
add user settings / preferences
Diffstat (limited to 'templates')
-rw-r--r--templates/left_side_navigation.php4
-rw-r--r--templates/preferences_form.php37
-rw-r--r--templates/preferences_page.php4
-rw-r--r--templates/settings_field.php14
-rw-r--r--templates/unread_indicator.php12
5 files changed, 66 insertions, 5 deletions
diff --git a/templates/left_side_navigation.php b/templates/left_side_navigation.php
index 012cf23..4cf8b55 100644
--- a/templates/left_side_navigation.php
+++ b/templates/left_side_navigation.php
@@ -11,6 +11,10 @@ if ($user != null) {
'icon' => 'person-add-outline',
'label' => __('navigation.followRequests'),
'unreadCount' => FollowRelation::countWhere("object = ? AND status = 'pending'", [$user->actor->id])
+ ], [
+ 'href' => '/preferences',
+ 'icon' => 'tune',
+ 'label' => __('preferences.pageTitle')
]];
if ($user->isAdmin) {
$links[] = ['href' => '/admin/settings/instance', 'icon' => 'settings-outline', 'label' => __('navigation.instanceSettings')];
diff --git a/templates/preferences_form.php b/templates/preferences_form.php
new file mode 100644
index 0000000..8c8f203
--- /dev/null
+++ b/templates/preferences_form.php
@@ -0,0 +1,37 @@
+<?php
+use Digitigrade\UserSettings;
+
+$settings = new UserSettings($user);
+?>
+<form class="settings" method="post" action="/todo" hx-post="/fragment/preferences" hx-disabled-elt="find button"
+ hx-swap="outerHTML">
+
+ <?php
+ call_template('settings_field', [
+ 'id' => 'pref-requestToFollow',
+ 'fieldName' => 'requestToFollow',
+ 'name' => __('preferences.requestToFollow.name'),
+ 'description' => __('preferences.requestToFollow.description'),
+ 'value' => $user->actor->requestToFollow,
+ 'type' => 'boolean'
+ ]);
+ call_template('settings_field', [
+ 'id' => 'pref-smallIndicators',
+ 'fieldName' => 'smallIndicators',
+ 'name' => __('preferences.smallIndicators.name'),
+ 'description' => __('preferences.smallIndicators.description'),
+ 'value' => $settings->getBool('interface.smallUnreadIndicators'),
+ 'type' => 'boolean'
+ ]);
+ ?>
+
+ <div class="row">
+ <div>
+ <?php if ($saved ?? false): ?>
+ <span class="temporaryIndicator"><?= __('form.saved') ?></span>
+ <?php endif; ?>
+ </div>
+ <button class="primary"><?= __('form.saveChanges') ?></button>
+ </div>
+
+</form> \ No newline at end of file
diff --git a/templates/preferences_page.php b/templates/preferences_page.php
new file mode 100644
index 0000000..bcb39b6
--- /dev/null
+++ b/templates/preferences_page.php
@@ -0,0 +1,4 @@
+<?php call_template('skeleton', ['pageTitle' => __('preferences.pageTitle')], function () {
+ global $user, $saved;
+ call_template('preferences_form', ['user' => $user, 'saved' => $saved ?? false]);
+}); \ No newline at end of file
diff --git a/templates/settings_field.php b/templates/settings_field.php
index 1ebbfb3..fe68a52 100644
--- a/templates/settings_field.php
+++ b/templates/settings_field.php
@@ -1,13 +1,14 @@
<?php
-$id = "setting-$key";
+$id ??= "setting-$key";
$settingType = $type ?? 'text';
$inputType = $settingType;
if ($settingType == 'boolean') {
- $inputType = 'select';
- $options = ['true', 'false'];
+ $inputType = 'checkbox';
+ $options = ['false', 'true'];
+ $checked = $value == 'true' || $value == true;
}
// php converts . to _ in $_POST for some mikuforsaken reason so i'm working around it like this
-$fieldName = str_replace('.', '<DOT>', $key);
+$fieldName ??= str_replace('.', '<DOT>', $key);
?>
<div class="row">
@@ -24,6 +25,11 @@ $fieldName = str_replace('.', '<DOT>', $key);
<?php endforeach; ?>
</select>
+ <?php elseif ($inputType == 'checkbox'): ?>
+
+ <input type="hidden" name="<?= $fieldName ?>" value="<?= $options[0] ?>">
+ <input id="<?= $id ?>" name="<?= $fieldName ?>" value="<?= $options[1] ?>" type="checkbox" <?= $checked ? 'checked' : '' ?> autocomplete="off">
+
<?php elseif ($inputType == 'longtext'): ?>
<textarea id="<?= $id ?>" name="<?= $fieldName ?>" autocomplete="off"><?= $value ?></textarea>
diff --git a/templates/unread_indicator.php b/templates/unread_indicator.php
index bacacc3..ecfcb43 100644
--- a/templates/unread_indicator.php
+++ b/templates/unread_indicator.php
@@ -1 +1,11 @@
-<span class="unreadIndicator"><?= $count ?></span> \ No newline at end of file
+<?php
+use Digitigrade\Model\UserAccount;
+use Digitigrade\UserSettings;
+
+$user = UserAccount::findByCurrentSession();
+$small = false;
+if ($user != null) {
+ $small = (new UserSettings($user))->getBool('interface.smallUnreadIndicators') ?? false;
+}
+?>
+<span class="unreadIndicator <?= $small ? 'reduced' : '' ?>"><?= $count ?></span> \ No newline at end of file