Skip to content

Commit

Permalink
allow user to display birth-year only (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
pplulee authored Jan 20, 2024
1 parent 6a2dff0 commit 0b85e3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import 'dayjs/locale/fi';
import 'dayjs/locale/ro';
import 'dayjs/locale/te';
import 'dayjs/locale/lt';
import 'dayjs/locale/lt';
import 'dayjs/locale/sk';
import 'dayjs/locale/sv';
import 'dayjs/locale/fa';
Expand Down Expand Up @@ -74,6 +73,7 @@ app.initializers.add('datlechin/flarum-birthdays', () => {

if (user.showDobDate() && user.showDobYear()) birthday = dayjs(birthday).locale(userLocale).format(dateFormat);
else if (user.showDobDate() === true && user.showDobYear() === false) birthday = dayjs(birthday).format(dateNoneYearFormat);
else if (user.showDobDate() === false && user.showDobYear() === true) birthday = dayjs(birthday).locale(userLocale).format('YYYY');
else return;

items.add(
Expand Down Expand Up @@ -149,7 +149,7 @@ app.initializers.add('datlechin/flarum-birthdays', () => {
onchange={(value) => {
this.showDobDateLoading = true;

this.user.save({ showDobDate: value, showDobYear: value }).then(() => {
this.user.save({ showDobDate: value}).then(() => {
this.showDobDateLoading = false;
m.redraw();
});
Expand All @@ -159,7 +159,7 @@ app.initializers.add('datlechin/flarum-birthdays', () => {
{app.translator.trans('datlechin-birthdays.forum.settings.show_dob_date_label')}
</Switch>
<Switch
state={this.user.showDobDate() && this.user.showDobYear()}
state={this.user.showDobYear()}
onchange={(value) => {
this.showDobYearLoading = true;

Expand All @@ -168,7 +168,7 @@ app.initializers.add('datlechin/flarum-birthdays', () => {
m.redraw();
});
}}
loading={this.showDobYearLoading || this.showDobDateLoading}
loading={this.showDobYearLoading}
>
{app.translator.trans('datlechin-birthdays.forum.settings.show_dob_year_label')}
</Switch>
Expand Down
9 changes: 6 additions & 3 deletions src/Listeners/SaveBirthdayToDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ public function handle(Saving $event): void

$actor->assertCan('editBirthday', $user);

$user->showDobDate = $attributes['showDobDate'] ?? false;
$user->showDobYear = $attributes['showDobYear'] ?? false;

if (isset($attributes['showDobDate'])) {
$user->showDobDate = $attributes['showDobDate'];
}
if (isset($attributes['showDobYear'])) {
$user->showDobYear = $attributes['showDobYear'];
}
if (isset($attributes['birthday'])) {
$user->birthday = $attributes['birthday'] === '' ? null : $attributes['birthday'];
}
Expand Down

0 comments on commit 0b85e3d

Please sign in to comment.