Skip to content

Commit

Permalink
User Avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
Fi1osof committed Mar 5, 2021
1 parent ee6b807 commit f236558
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 16 deletions.
2 changes: 1 addition & 1 deletion next.config.js
Expand Up @@ -10,7 +10,7 @@ const webpack = (config, options) => {
*/
config.plugins.push(
new MomentLocalesPlugin({
localesToKeep: ['ru', 'en'],
localesToKeep: ['ru'],
})
)

Expand Down
8 changes: 8 additions & 0 deletions server/nexus/generated/nexus.ts
Expand Up @@ -473,13 +473,15 @@ export interface NexusGenObjects {
// root type
Attributes?: NexusGenRootTypes['UserAttributes'] | null // UserAttributes
active: boolean // Boolean!
createdon: NexusGenScalars['DateTime'] // DateTime!
id: number // Int!
username?: string | null // String
}
UserAttributes: {
// root type
fullname: string // String!
id: number // Int!
photo: string // String!
}
bani684_site_tmplvar_contentvalues: {
// root type
Expand Down Expand Up @@ -588,14 +590,17 @@ export interface NexusGenFieldTypes {
// field return type
Attributes: NexusGenRootTypes['UserAttributes'] | null // UserAttributes
active: boolean // Boolean!
createdon: NexusGenScalars['DateTime'] // DateTime!
fullname: string | null // String
id: number // Int!
image: string | null // String
username: string | null // String
}
UserAttributes: {
// field return type
fullname: string // String!
id: number // Int!
photo: string // String!
}
bani684_site_tmplvar_contentvalues: {
// field return type
Expand Down Expand Up @@ -683,14 +688,17 @@ export interface NexusGenFieldTypeNames {
// field return type name
Attributes: 'UserAttributes'
active: 'Boolean'
createdon: 'DateTime'
fullname: 'String'
id: 'Int'
image: 'String'
username: 'String'
}
UserAttributes: {
// field return type name
fullname: 'String'
id: 'Int'
photo: 'String'
}
bani684_site_tmplvar_contentvalues: {
// field return type name
Expand Down
7 changes: 7 additions & 0 deletions server/nexus/generated/schema.graphql
Expand Up @@ -278,8 +278,14 @@ input StringNullableFilter {
type User {
Attributes: UserAttributes
active: Boolean!
createdon: DateTime!
fullname: String
id: Int!

"""
Аватар
"""
image: String
username: String
}

Expand All @@ -289,6 +295,7 @@ type User {
type UserAttributes {
fullname: String!
id: Int!
photo: String!
}

input bani684_site_contentOrderByInput {
Expand Down
11 changes: 11 additions & 0 deletions server/nexus/types/Query/definitions/User.ts
Expand Up @@ -7,6 +7,7 @@ const select = {
active: true,
username: true,
sudo: true,
createdon: true,
Attributes: true,
}

Expand Down Expand Up @@ -47,6 +48,16 @@ export default (t: ObjectDefinitionBlock<'Query'>) => {
...variables,
select,
})
// .then((users) => {

// return users.map((user) => {

// return {
// ...user,
// createdon: new Date(user.createdon * 1000),
// }
// })
// })
},
})
}
14 changes: 12 additions & 2 deletions server/nexus/types/User/index.ts
Expand Up @@ -11,6 +11,7 @@ export const UserAttributes = objectType({
definition(t) {
t.nonNull.int('id')
t.nonNull.string('fullname')
t.nonNull.string('photo')
},
})

Expand All @@ -25,10 +26,19 @@ export const User = objectType({
t.nonNull.int('id')
t.nonNull.boolean('active')
// t.nonNull.boolean('blocked')
// t.nonNull.date('createdon')
t.nonNull.date('createdon')
// t.string('email')
t.string('username')
// t.string('image')
t.string('image', {
description: 'Аватар',
resolve(user) {
const image = user.Attributes?.photo || 'anonymous.jpg'

return image.startsWith('lazy/')
? `assets/images/${image}`
: `assets/society/uploads/images/${image}`
},
})
// t.boolean('sudo')

t.field('Attributes', {
Expand Down
20 changes: 13 additions & 7 deletions src/components/ui/Link/User/index.tsx
@@ -1,21 +1,27 @@
import React, { useMemo } from 'react'
import { imageFormats } from 'src/helpers/imageFormats'

import Link from '..'
import { UserLinkProps } from './interfaces'
import { UserLinkStyled } from './styled'

/**
* Ссылка на страницу пользователя
*/
const UserLink: React.FC<UserLinkProps> = ({ user, ...other }) => {
return useMemo(() => {
return (
<Link
href={`/profile/${user.username}`}
title={user.fullname || user.username || undefined}
{...other}
>
{user.fullname || user.username}
</Link>
<UserLinkStyled {...other}>
<Link
href={`/profile/${user.username}`}
title={user.fullname || user.username || undefined}
>
{user.image && (
<img src={imageFormats(user.image, 'thumb')} className="avatar" />
)}{' '}
{user.fullname || user.username}
</Link>
</UserLinkStyled>
)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [other, user.username])
Expand Down
9 changes: 9 additions & 0 deletions src/components/ui/Link/User/styled.ts
@@ -0,0 +1,9 @@
import styled from 'styled-components'

export const UserLinkStyled = styled.span`
img.avatar {
border-radius: 50%;
height: 40px;
width: 40px;
}
`
2 changes: 2 additions & 0 deletions src/gql/users.graphql
Expand Up @@ -20,4 +20,6 @@ fragment user_ on User {
username
fullname
active
createdon
image
}
9 changes: 6 additions & 3 deletions src/modules/gql/generated/helpers/apollo-helpers.ts
Expand Up @@ -71,18 +71,21 @@ export type ResourceFieldPolicy = {
template?: FieldPolicy<any> | FieldReadFunction<any>,
uri?: FieldPolicy<any> | FieldReadFunction<any>
};
export type UserKeySpecifier = ('Attributes' | 'active' | 'fullname' | 'id' | 'username' | UserKeySpecifier)[];
export type UserKeySpecifier = ('Attributes' | 'active' | 'createdon' | 'fullname' | 'id' | 'image' | 'username' | UserKeySpecifier)[];
export type UserFieldPolicy = {
Attributes?: FieldPolicy<any> | FieldReadFunction<any>,
active?: FieldPolicy<any> | FieldReadFunction<any>,
createdon?: FieldPolicy<any> | FieldReadFunction<any>,
fullname?: FieldPolicy<any> | FieldReadFunction<any>,
id?: FieldPolicy<any> | FieldReadFunction<any>,
image?: FieldPolicy<any> | FieldReadFunction<any>,
username?: FieldPolicy<any> | FieldReadFunction<any>
};
export type UserAttributesKeySpecifier = ('fullname' | 'id' | UserAttributesKeySpecifier)[];
export type UserAttributesKeySpecifier = ('fullname' | 'id' | 'photo' | UserAttributesKeySpecifier)[];
export type UserAttributesFieldPolicy = {
fullname?: FieldPolicy<any> | FieldReadFunction<any>,
id?: FieldPolicy<any> | FieldReadFunction<any>
id?: FieldPolicy<any> | FieldReadFunction<any>,
photo?: FieldPolicy<any> | FieldReadFunction<any>
};
export type bani684_site_tmplvar_contentvaluesKeySpecifier = ('contentid' | 'id' | 'tmplvarid' | 'value' | bani684_site_tmplvar_contentvaluesKeySpecifier)[];
export type bani684_site_tmplvar_contentvaluesFieldPolicy = {
Expand Down
44 changes: 44 additions & 0 deletions src/modules/gql/generated/schema.json
Expand Up @@ -2578,6 +2578,22 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdon",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "DateTime",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "fullname",
"description": null,
Expand Down Expand Up @@ -2606,6 +2622,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "image",
"description": "Аватар",
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "username",
"description": null,
Expand Down Expand Up @@ -2660,6 +2688,22 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "photo",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/gql/generated/types.ts
Expand Up @@ -281,8 +281,11 @@ export interface User {
__typename?: 'User';
Attributes?: Maybe<UserAttributes>;
active: Scalars['Boolean'];
createdon: Scalars['DateTime'];
fullname?: Maybe<Scalars['String']>;
id: Scalars['Int'];
/** Аватар */
image?: Maybe<Scalars['String']>;
username?: Maybe<Scalars['String']>;
}

Expand All @@ -291,6 +294,7 @@ export interface UserAttributes {
__typename?: 'UserAttributes';
fullname: Scalars['String'];
id: Scalars['Int'];
photo: Scalars['String'];
}

export interface Bani684SiteContentOrderByInput {
Expand Down
4 changes: 3 additions & 1 deletion src/modules/gql/generated/user_.ts
Expand Up @@ -9,13 +9,15 @@
import * as Types from './types';

import { gql } from '@apollo/client';
export type UserFragment = { __typename?: 'User', id: number, username?: Types.Maybe<string>, fullname?: Types.Maybe<string>, active: boolean };
export type UserFragment = { __typename?: 'User', id: number, username?: Types.Maybe<string>, fullname?: Types.Maybe<string>, active: boolean, createdon: globalThis.Date, image?: Types.Maybe<string> };

export const UserFragmentDoc = gql`
fragment user_ on User {
id
username
fullname
active
createdon
image
}
`;
5 changes: 4 additions & 1 deletion src/pages/Users/View/User/index.tsx
Expand Up @@ -5,6 +5,7 @@ import {
} from 'src/components/ui/GridTable/styles'
import UserLink from 'src/components/ui/Link/User'
import { UsersPageViewUserProps } from './interfaces'
import moment from 'moment'

const UsersPageViewUser: React.FC<UsersPageViewUserProps> = ({
user,
Expand All @@ -16,7 +17,9 @@ const UsersPageViewUser: React.FC<UsersPageViewUserProps> = ({
<GridTableAttributeStyled>
<UserLink user={user} />
</GridTableAttributeStyled>
<GridTableAttributeStyled>Дава регистрации</GridTableAttributeStyled>
<GridTableAttributeStyled>
{moment(user.createdon).format('DD-MM-YYYY')}
</GridTableAttributeStyled>

{/* <GridTableAttributeStyled>Email</GridTableAttributeStyled> */}
</GridTableItemStyled>
Expand Down
1 change: 0 additions & 1 deletion src/pages/Users/index.tsx
Expand Up @@ -15,7 +15,6 @@ import { ParsedUrlQuery } from 'querystring'
const take = 10

const defaultVariables: UsersQueryVariables = {
where: {},
take,
}

Expand Down
3 changes: 3 additions & 0 deletions src/pages/_App/index.tsx
Expand Up @@ -26,6 +26,9 @@ import ErrorPage from '../_Error'
import Layout from './Layout'
import { AppContext, AppContextValue } from './Context'
import { GlobalStyle } from 'src/theme/GlobalStyle'
import moment from 'moment'

moment.locale('ru')

// import chalk from 'chalk';
// import Debug from 'debug';
Expand Down

0 comments on commit f236558

Please sign in to comment.