mirror of https://github.com/immich-app/immich.git
feat(web,server): user avatar color (#4779)
parent
14c7187539
commit
d25a245049
@ -0,0 +1,14 @@
|
||||
# openapi.model.UserAvatarColor
|
||||
|
||||
## Load the model package
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
```
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@ -0,0 +1,109 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
|
||||
class UserAvatarColor {
|
||||
/// Instantiate a new enum with the provided [value].
|
||||
const UserAvatarColor._(this.value);
|
||||
|
||||
/// The underlying value of this enum member.
|
||||
final String value;
|
||||
|
||||
@override
|
||||
String toString() => value;
|
||||
|
||||
String toJson() => value;
|
||||
|
||||
static const primary = UserAvatarColor._(r'primary');
|
||||
static const pink = UserAvatarColor._(r'pink');
|
||||
static const red = UserAvatarColor._(r'red');
|
||||
static const yellow = UserAvatarColor._(r'yellow');
|
||||
static const blue = UserAvatarColor._(r'blue');
|
||||
static const green = UserAvatarColor._(r'green');
|
||||
static const purple = UserAvatarColor._(r'purple');
|
||||
static const orange = UserAvatarColor._(r'orange');
|
||||
static const gray = UserAvatarColor._(r'gray');
|
||||
static const amber = UserAvatarColor._(r'amber');
|
||||
|
||||
/// List of all possible values in this [enum][UserAvatarColor].
|
||||
static const values = <UserAvatarColor>[
|
||||
primary,
|
||||
pink,
|
||||
red,
|
||||
yellow,
|
||||
blue,
|
||||
green,
|
||||
purple,
|
||||
orange,
|
||||
gray,
|
||||
amber,
|
||||
];
|
||||
|
||||
static UserAvatarColor? fromJson(dynamic value) => UserAvatarColorTypeTransformer().decode(value);
|
||||
|
||||
static List<UserAvatarColor>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <UserAvatarColor>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = UserAvatarColor.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
}
|
||||
|
||||
/// Transformation class that can [encode] an instance of [UserAvatarColor] to String,
|
||||
/// and [decode] dynamic data back to [UserAvatarColor].
|
||||
class UserAvatarColorTypeTransformer {
|
||||
factory UserAvatarColorTypeTransformer() => _instance ??= const UserAvatarColorTypeTransformer._();
|
||||
|
||||
const UserAvatarColorTypeTransformer._();
|
||||
|
||||
String encode(UserAvatarColor data) => data.value;
|
||||
|
||||
/// Decodes a [dynamic value][data] to a UserAvatarColor.
|
||||
///
|
||||
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
|
||||
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
|
||||
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
|
||||
///
|
||||
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
|
||||
/// and users are still using an old app with the old code.
|
||||
UserAvatarColor? decode(dynamic data, {bool allowNull = true}) {
|
||||
if (data != null) {
|
||||
switch (data) {
|
||||
case r'primary': return UserAvatarColor.primary;
|
||||
case r'pink': return UserAvatarColor.pink;
|
||||
case r'red': return UserAvatarColor.red;
|
||||
case r'yellow': return UserAvatarColor.yellow;
|
||||
case r'blue': return UserAvatarColor.blue;
|
||||
case r'green': return UserAvatarColor.green;
|
||||
case r'purple': return UserAvatarColor.purple;
|
||||
case r'orange': return UserAvatarColor.orange;
|
||||
case r'gray': return UserAvatarColor.gray;
|
||||
case r'amber': return UserAvatarColor.amber;
|
||||
default:
|
||||
if (!allowNull) {
|
||||
throw ArgumentError('Unknown enum value to decode: $data');
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Singleton [UserAvatarColorTypeTransformer] instance.
|
||||
static UserAvatarColorTypeTransformer? _instance;
|
||||
}
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
import 'package:openapi/api.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
// tests for UserAvatarColor
|
||||
void main() {
|
||||
|
||||
group('test UserAvatarColor', () {
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddAvatarColor1699889987493 implements MigrationInterface {
|
||||
name = 'AddAvatarColor1699889987493'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "users" ADD "avatarColor" character varying`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "avatarColor"`);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { mdiClose } from '@mdi/js';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { UserAvatarColor, UserResponseDto } from '@api';
|
||||
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
||||
import FullScreenModal from '../full-screen-modal.svelte';
|
||||
import UserAvatar from '../user-avatar.svelte';
|
||||
|
||||
export let user: UserResponseDto;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const colors: UserAvatarColor[] = Object.values(UserAvatarColor);
|
||||
</script>
|
||||
|
||||
<FullScreenModal on:clickOutside={() => dispatch('close')} on:escape={() => dispatch('close')}>
|
||||
<div class="flex h-full w-full place-content-center place-items-center overflow-hidden">
|
||||
<div
|
||||
class=" rounded-3xl border bg-immich-bg shadow-sm dark:border-immich-dark-gray dark:bg-immich-dark-gray dark:text-immich-dark-fg p-4"
|
||||
>
|
||||
<div class="flex items-center">
|
||||
<h1 class="px-4 w-full self-center font-medium text-immich-primary dark:text-immich-dark-primary text-sm">
|
||||
SELECT AVATAR COLOR
|
||||
</h1>
|
||||
<div>
|
||||
<CircleIconButton icon={mdiClose} on:click={() => dispatch('close')} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-center p-4 mt-4">
|
||||
<div class="grid grid-cols-2 md:grid-cols-5 gap-4">
|
||||
{#each colors as color}
|
||||
<button on:click={() => dispatch('choose', color)}>
|
||||
<UserAvatar {user} {color} size="xl" showProfileImage={false} />
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</FullScreenModal>
|
||||
Loading…
Reference in New Issue