DEV: migrates username-preference to gjs (#27864)

This commit is contained in:
Joffrey JAFFEUX 2024-07-11 13:28:49 +02:00 committed by GitHub
parent 015a38d014
commit 5cdd6d7c37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 67 additions and 58 deletions

View File

@ -1,13 +1,19 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { Input } from "@ember/component";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { empty, or } from "@ember/object/computed";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import { isEmpty } from "@ember/utils";
import DButton from "discourse/components/d-button";
import DModalCancel from "discourse/components/d-modal-cancel";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { setting } from "discourse/lib/computed";
import DiscourseURL, { userPath } from "discourse/lib/url";
import User from "discourse/models/user";
import i18n from "discourse-common/helpers/i18n";
import I18n from "discourse-i18n";
export default class UsernamePreference extends Component {
@ -97,4 +103,65 @@ export default class UsernamePreference extends Component {
},
});
}
<template>
{{#if this.editing}}
<form class="form-horizontal">
<div class="control-group">
<Input
{{on "input" this.onInput}}
@value={{this.newUsername}}
maxlength={{this.maxLength}}
class="input-xxlarge username-preference__input"
/>
<div class="instructions">
<p>
{{#if this.taken}}
{{i18n "user.change_username.taken"}}
{{/if}}
<span>{{this.errorMessage}}</span>
</p>
</div>
</div>
<div class="control-group">
<DButton
@action={{this.changeUsername}}
@disabled={{this.saveDisabled}}
@translatedLabel={{this.saveButtonText}}
type="submit"
class="btn-primary username-preference__submit"
/>
<DModalCancel @close={{this.toggleEditing}} />
{{#if this.saved}}{{i18n "saved"}}{{/if}}
</div>
</form>
{{else}}
<div class="controls">
<span
class="static username-preference__current-username"
>{{@user.username}}</span>
{{#if @user.can_edit_username}}
<DButton
@action={{this.toggleEditing}}
@icon="pencil-alt"
@title="user.username.edit"
class="btn-small username-preference__edit-username"
/>
{{/if}}
</div>
{{#if this.siteSettings.enable_mentions}}
<div class="instructions">
{{htmlSafe
(i18n "user.username.short_instructions" username=@user.username)
}}
</div>
{{/if}}
{{/if}}
</template>
}

View File

@ -1,58 +0,0 @@
{{#if this.editing}}
<form class="form-horizontal">
<div class="control-group">
<Input
{{on "input" this.onInput}}
@value={{this.newUsername}}
maxlength={{this.maxLength}}
class="input-xxlarge username-preference__input"
/>
<div class="instructions">
<p>
{{#if this.taken}}
{{i18n "user.change_username.taken"}}
{{/if}}
<span>{{this.errorMessage}}</span>
</p>
</div>
</div>
<div class="control-group">
<DButton
@action={{this.changeUsername}}
@disabled={{this.saveDisabled}}
@translatedLabel={{this.saveButtonText}}
type="submit"
class="btn-primary username-preference__submit"
/>
<DModalCancel @close={{this.toggleEditing}} />
{{#if this.saved}}{{i18n "saved"}}{{/if}}
</div>
</form>
{{else}}
<div class="controls">
<span
class="static username-preference__current-username"
>{{@user.username}}</span>
{{#if @user.can_edit_username}}
<DButton
@action={{fn this.toggleEditing @user}}
@icon="pencil-alt"
@title="user.username.edit"
class="btn-small username-preference__edit-username"
/>
{{/if}}
</div>
{{#if this.siteSettings.enable_mentions}}
<div class="instructions">
{{html-safe
(i18n "user.username.short_instructions" username=@user.username)
}}
</div>
{{/if}}
{{/if}}