Skip to content

Commit

Permalink
Merge branch 'v4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclofabbro committed Feb 5, 2024
2 parents 0572910 + f191a9b commit fd9f45c
Show file tree
Hide file tree
Showing 351 changed files with 74,473 additions and 169,631 deletions.
1 change: 1 addition & 0 deletions .eslintrc-base
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
// "fixMixedExportsWithInlineTypeSpecifier": true
// }
// ],
"@typescript-eslint/switch-exhaustiveness-check": "error",
"no-mixed-spaces-and-tabs": ["off"],
// "react/react-in-jsx-scope": 0,
"react/react-in-jsx-scope": "off",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { t } from '@lingui/macro'
import {
isEdgeNodeOfType,
narrowNodeType,
} from '@moodlenet/common/dist/graphql/helpers'
import { ID } from '@moodlenet/common/dist/graphql/scalars.graphql'
import { AssetRefInput } from '@moodlenet/common/dist/graphql/types.graphql.gen'
import { isEdgeNodeOfType, narrowNodeType } from '@moodlenet/common/dist/graphql/helpers'
import type { ID } from '@moodlenet/common/dist/graphql/scalars.graphql'
import type { AssetRefInput } from '@moodlenet/common/dist/graphql/types.graphql.gen'
import { fileExceedsMaxUploadSize } from '@moodlenet/common/dist/staticAsset/lib'
import { useFormik } from 'formik'
import { createElement, useCallback, useEffect, useMemo } from 'react'
import { mixed, object, SchemaOf, string } from 'yup'
import {
MIN_RESOURCES_FOR_USER_APPROVAL_REQUESTS,
MNEnv,
} from '../../../../../constants'
import type { SchemaOf } from 'yup'
import { mixed, object, string } from 'yup'
import { MIN_RESOURCES_FOR_USER_APPROVAL_REQUESTS, MNEnv } from '../../../../../constants'
import { useLocalInstance } from '../../../../../context/Global/LocalInstance'
import { useSeoContentId } from '../../../../../context/Global/Seo'
import { useSession } from '../../../../../context/Global/Session'
Expand All @@ -23,14 +18,15 @@ import {
} from '../../../../../helpers/data'
import { mainPath } from '../../../../../hooks/glob/nav'
import { href } from '../../../../elements/link'
import { ctrlHook, CtrlHook } from '../../../../lib/ctrl'
import type { CtrlHook } from '../../../../lib/ctrl'
import { ctrlHook } from '../../../../lib/ctrl'
import { useCollectionCardCtrl } from '../../../molecules/cards/CollectionCard/Ctrl/CollectionCardCtrl'
import { useResourceCardCtrl } from '../../../molecules/cards/ResourceCard/Ctrl/ResourceCardCtrl'
import { useHeaderPageTemplateCtrl } from '../../../templates/HeaderPageTemplateCtrl/HeaderPageTemplateCtrl'
import { fallbackProps } from '../../Extra/Fallback/Ctrl/FallbackCtrl'
import { Fallback } from '../../Extra/Fallback/Fallback'
import { ProfileProps } from '../Profile'
import { ProfileFormValues } from '../types'
import type { ProfileProps } from '../Profile'
import type { ProfileFormValues } from '../types'
import {
useAddProfileRelationMutation,
useDelProfileRelationMutation,
Expand All @@ -39,16 +35,14 @@ import {
useSendEmailToProfileMutation,
} from './ProfileCtrl.gen'

// TODO //@ETTO: LOOK ETTORE FOR FORM

const validationSchema: SchemaOf<ProfileFormValues> = object({
avatarImage: mixed()
.test((v, { createError }) =>
v instanceof Blob && fileExceedsMaxUploadSize(v.size, MNEnv.maxUploadSize)
? createError({
message: t`The image is too big, reduce the size or use another image`,
})
: true
: true,
)
.optional(),
backgroundImage: mixed()
Expand All @@ -57,7 +51,7 @@ const validationSchema: SchemaOf<ProfileFormValues> = object({
? createError({
message: t`The image is too big, reduce the size or use another image`,
})
: true
: true,
)
.optional(),
displayName: string()
Expand All @@ -73,9 +67,7 @@ const newCollectionHref = href(mainPath.createNewCollection)
const newResourceHref = href(mainPath.createNewResource)

export type ProfileCtrlProps = { id: ID }
export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({
id,
}) => {
export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({ id }) => {
useSeoContentId(id)
const {
isAuthenticated,
Expand Down Expand Up @@ -116,7 +108,7 @@ export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({
(profile?.collections.edges || [])
.filter(isEdgeNodeOfType(['Collection']))
.map(({ node }) => node),
[profile?.collections.edges]
[profile?.collections.edges],
)
const [edit, editProfile] = useEditProfileMutation()
const [addRelation, addRelationRes] = useAddProfileRelationMutation()
Expand All @@ -128,16 +120,13 @@ export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({
(profile?.resources.edges || [])
.filter(isEdgeNodeOfType(['Resource']))
.map(({ node }) => node),
[profile?.resources.edges]
[profile?.resources.edges],
)

const kudos = useMemo(
() =>
[...resources, ...collections].reduce(
(allLikes, { likesCount }) => allLikes + likesCount,
0
),
[collections, resources]
[...resources, ...collections].reduce((allLikes, { likesCount }) => allLikes + likesCount, 0),
[collections, resources],
)
const myFollowEdgeId = profile?.myFollow.edges[0]?.edge.id
const toggleFollowForm = useFormik({
Expand Down Expand Up @@ -199,14 +188,13 @@ export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({
const form = useFormik<ProfileFormValues>({
validationSchema,
initialValues: { description: '', displayName: '' },
onSubmit: async (vals) => {
onSubmit: async vals => {
if (!form.dirty || editProfile.loading) {
return
}

const imageAssetRef: AssetRefInput =
!vals.backgroundImage ||
vals.backgroundImage === form.initialValues.backgroundImage
!vals.backgroundImage || vals.backgroundImage === form.initialValues.backgroundImage
? { location: '', type: 'NoChange' }
: typeof vals.backgroundImage === 'string'
? {
Expand Down Expand Up @@ -290,10 +278,7 @@ export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({
},
},
})
if (
_published &&
editResp.data?.editNode.__typename === 'EditNodeMutationSuccess'
) {
if (_published && editResp.data?.editNode.__typename === 'EditNodeMutationSuccess') {
await sendEmailMut({
variables: {
text: 'Congratulations! Your account has been approved!',
Expand All @@ -302,7 +287,7 @@ export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({
})
}
},
[edit, isAdmin, profile, sendEmailMut]
[edit, isAdmin, profile, sendEmailMut],
)
const sendEmailForm = useFormik<{ text: string }>({
initialValues: { text: '' },
Expand All @@ -326,17 +311,13 @@ export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({
const userId = `${profile.id.split('/')![1]}@${localOrg.domain}`

const props: ProfileProps = {
headerPageTemplateProps: ctrlHook(
useHeaderPageTemplateCtrl,
{},
'header-page-template'
),
headerPageTemplateProps: ctrlHook(useHeaderPageTemplateCtrl, {}, 'header-page-template'),
isOwner: isMe,
resourceCardPropsList: resources.map(({ id }) =>
ctrlHook(useResourceCardCtrl, { id, removeAction: false }, id)
ctrlHook(useResourceCardCtrl, { id, removeAction: false }, id),
),
collectionCardPropsList: collections.map(({ id }) =>
ctrlHook(useCollectionCardCtrl, { id }, id)
ctrlHook(useCollectionCardCtrl, { id }, id),
),
overallCardProps: {
followers: profile.followersCount,
Expand All @@ -359,8 +340,7 @@ export const useProfileCtrl: CtrlHook<ProfileProps, ProfileCtrlProps> = ({
isApproved: profile._published,
requestApprovalForm,
isElegibleForApproval:
profile.resourcesCount >=
(MIN_RESOURCES_FOR_USER_APPROVAL_REQUESTS ?? 0),
profile.resourcesCount >= (MIN_RESOURCES_FOR_USER_APPROVAL_REQUESTS ?? 0),
isWaitingApproval,
showAccountApprovedSuccessAlert: hasJustBeenApproved,
unapproveUserForm,
Expand Down
2 changes: 1 addition & 1 deletion legacy-packages/webapp/src/ui/styles/utils/_colors.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$base-light-green-color: #00bd7e;
$base-light-red-color: rgb(255, 49, 49);
$base-light-red-color: #ff3131;
$base-moodle-color: #f88012;
$base-electric-blue-color: #1a6aff;
$base-black-color: #212121;
Expand Down
2 changes: 1 addition & 1 deletion notes/react-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ produce packge.json c0on tutti i package e li risolv

packages/react-app/src/webapp/components.mts export similar

//TODO //@ALE //@ETTO
//TODO //@ALE

il package dovrebbe avere 3 cartelle, common, webapp, server
Loading

0 comments on commit fd9f45c

Please sign in to comment.