Skip to content

Commit

Permalink
server|ui: add public names for authors
Browse files Browse the repository at this point in the history
used when exporting a karaoke / in webhooks
  • Loading branch information
odrling committed Jan 31, 2025
1 parent a02b3bd commit d1ee9e3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
4 changes: 3 additions & 1 deletion server/authors.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func GetAuthor(ctx context.Context, input *GetAuthorInput) (*AuthorOutput, error
}

type AuthorInfo struct {
Name string `json:"name"`
Name string `json:"name"`
PublicName string `json:"external_name,omitempty"`
}

type CreateAuthorInput struct {
Expand Down Expand Up @@ -104,6 +105,7 @@ func UpdateAuthor(ctx context.Context, input *UpdateAuthorInput) (*AuthorOutput,

func (info AuthorInfo) to_TimingAuthor(author *TimingAuthor) error {
author.Name = info.Name
author.PublicName = info.PublicName
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions server/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ type User struct {

type TimingAuthor struct {
gorm.Model
Name string `gorm:"uniqueIndex:idx_timing_author_name"`
MugenID *uuid.UUID `gorm:"uniqueIndex:idx_timing_author_mugen_id"`
Name string `gorm:"uniqueIndex:idx_timing_author_name"`
MugenID *uuid.UUID `gorm:"uniqueIndex:idx_timing_author_mugen_id"`
PublicName string
}

func (name *TimingAuthor) BeforeSave(tx *gorm.DB) error {
Expand Down
6 changes: 5 additions & 1 deletion server/mugen.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,11 @@ func karaDescription(k KaraInfoDB) (string, error) {
if len(k.Authors) > 0 {
authors := make([]string, len(k.Authors))
for i, author := range k.Authors {
authors[i] = author.Name
if author.PublicName == "" {
authors[i] = author.Name
} else {
authors[i] = author.PublicName
}
}
authors_part := karaDescriptionPartList("Author", authors)

Expand Down
16 changes: 16 additions & 0 deletions ui/src/components/AuthorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ export default function AuthorEditor(props: {
reset?: boolean;
}) {
const [getName, setName] = createSignal(props.author?.Name ?? "");
const [getPublicName, setPublicName] = createSignal(
props.author?.PublicName ?? "",
);

const onsubmit: JSX.EventHandler<HTMLElement, SubmitEvent> = (e) => {
e.preventDefault();
props.onSubmit({
name: getName(),
external_name: getPublicName(),
});
if (props.reset) {
(e.target as HTMLFormElement).reset();
Expand All @@ -33,6 +37,18 @@ export default function AuthorEditor(props: {
onInput={(e) => setName(e.currentTarget.value)}
class="input input-bordered w-full"
/>
<div class="label">
<span class="label-text">External Name</span>
<span class="label-text-alt">(optional)</span>
</div>
<input
type="text"
required
placeholder="bebou69"
value={getPublicName()}
onInput={(e) => setPublicName(e.currentTarget.value)}
class="input input-bordered w-full"
/>
</label>

<input type="submit" class="btn btn-primary" />
Expand Down
2 changes: 2 additions & 0 deletions ui/src/pages/tags/author.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function TagsAuthor() {
<tr>
<th></th>
<th>Name</th>
<th>Public Name</th>
<th></th>
</tr>
</thead>
Expand All @@ -82,6 +83,7 @@ export default function TagsAuthor() {
<tr class="hover">
<th>{getAuthor().ID}</th>
<td>{getAuthor().Name}</td>
<td>{getAuthor().PublicName}</td>
<td class="flex gap-x-1">
<button
class="btn btn-sm btn-warning"
Expand Down

0 comments on commit d1ee9e3

Please sign in to comment.