Skip to content

Commit

Permalink
add create date resource functionality b00tc4mp#482
Browse files Browse the repository at this point in the history
  • Loading branch information
juditta99 committed May 8, 2024
1 parent e0248f6 commit 062ea98
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion staff/judy-grayland/project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The idea behind this app is to bring all available resources together in one pla
- title (string)
- description (string)
- tags ([Tag.id])
- date (date)
- date (date) <= NICE TO HAVE
- link (string)

#### Tag -topic- (xenofobia, bullying, dislexia)
Expand Down
17 changes: 6 additions & 11 deletions staff/judy-grayland/project/api/data/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,21 @@ const book = new Schema({
],
})

const specialDate = new Schema({
date: {
type: Date,
required: true,
},
const date = new Schema({
title: {
type: String,
required: true,
},
link: {
description: {
type: String,
required: true,
},
image: {
link: {
type: String,
},

tag: [
{
type: ObjectId,
ref: 'Theme',
},
],
})
Expand All @@ -144,7 +139,7 @@ const User = model('User', user)
const Resource = model('Resource', resource)
const Activity = model('Activity', activity)
const Book = model('Book', book)
const SpecialDate = model('SpecialDate', specialDate)
const Date = model('Date', date)

/*
eg. const colegio123 = new User({ name: 'Colegio 123' })
Expand All @@ -154,4 +149,4 @@ eg. const book = new Category({ name: 'Libro' })
*/

export { User, Resource, Activity, Book, SpecialDate }
export { User, Resource, Activity, Book, Date }
2 changes: 1 addition & 1 deletion staff/judy-grayland/project/api/logic/createResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function createResource({
// validate.ageRange(ageRange, 'ageRange')
}

if (resourceType === 'specialDate') {
if (resourceType === 'date') {
validate.text(link, 'link')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function createResource({
validate.text(image, 'image')
// validate.ageRange(ageRange, 'ageRange')
}
if (resourceType === 'specialDate') {
if (resourceType === 'date') {
validate.text(link, 'link')
}

Expand Down
16 changes: 5 additions & 11 deletions staff/judy-grayland/project/app/src/pages/NewResource.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ function NewResource() {
<Field
name="resourceType"
type="radio"
inputId="special-date-radio"
value="special-date"
checked={resourceType === 'special-date'}
onChange={() => setResourceType('special-date')}
inputId="date-radio"
value="date"
checked={resourceType === 'date'}
onChange={() => setResourceType('date')}
>
Fecha especial
</Field>
Expand Down Expand Up @@ -222,20 +222,14 @@ function NewResource() {
</fieldset>
</>
)}
{resourceType === 'special-date' && (
{resourceType === 'date' && (
<>
<Field name="title" inputId="title-input">
Título
</Field>
<Field name="date" inputId="date-input">
Autor
</Field>
<Field name="description" inputId="description-input">
Descripción
</Field>
<Field name="image" inputId="image-input">
Imagen
</Field>
<Field name="link" inputId="link-input">
Enlace
</Field>
Expand Down
2 changes: 1 addition & 1 deletion staff/judy-grayland/project/app/src/pages/ResourceBook.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button } from '../components'

function ResourceBook(props) {
return (
<article className="resource">
<article className="resource-book">
<span>Libro</span>
<h2>{props.title}</h2>

Expand Down
19 changes: 19 additions & 0 deletions staff/judy-grayland/project/app/src/pages/ResourceDate.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Button, Topic } from '../components'

function ResourceDate(props) {
return (
<article className="resource-date">
{/* We hardcode the type of resource because we already know what it is since this component is only rendered for this type of resource. If we write props.resourceType we get it from the database and it's in English */}

<span>Fecha especial</span>
<h2>{props.title}</h2>
<p>{props.description}</p>
<a>{props.link}</a>
<Topic topics={props.topic} />
<Button>Editar</Button>
<Button>Eliminar</Button>
</article>
)
}

export default ResourceDate
13 changes: 12 additions & 1 deletion staff/judy-grayland/project/app/src/pages/ResourcesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useNavigate } from 'react-router-dom'
import { useState, useEffect } from 'react'

import { Button } from '../components'
import { ResourceActivity, ResourceBook } from '.'
import { ResourceActivity, ResourceBook, ResourceDate } from '.'

import logic from '../logic'

Expand Down Expand Up @@ -49,6 +49,17 @@ function ResourcesList() {
/>
)
}
if (resource.resourceType === 'date') {
return (
<ResourceDate
key={resource._id}
title={resource.title}
description={resource.description}
link={resource.link}
topic={resource.topic}
/>
)
}

return (
<ResourceActivity
Expand Down
2 changes: 2 additions & 0 deletions staff/judy-grayland/project/app/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Profile from './Profile'
import Register from './Register'
import ResourceActivity from './ResourceActivity'
import ResourceBook from './ResourceBook'
import ResourceDate from './ResourceDate'
import ResourcesList from './ResourcesList'

export {
Expand All @@ -13,5 +14,6 @@ export {
Register,
ResourceActivity,
ResourceBook,
ResourceDate,
ResourcesList,
}
2 changes: 1 addition & 1 deletion staff/judy-grayland/project/shared/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function resourceType(resourceType, explain) {
if (
resourceType !== 'book' &&
resourceType !== 'activity' &&
resourceType !== 'specialDate'
resourceType !== 'date'
)
throw new TypeError(`${resourceType} is not a valid resource type`)
}
Expand Down

0 comments on commit 062ea98

Please sign in to comment.