| @ -0,0 +1,42 @@ | |||
| // _core : social/userPessoa | |||
| const dbComunidade = _db.queryFirst(` | |||
| SELECT | |||
| uid, | |||
| nome, | |||
| descricao, | |||
| imagem, | |||
| ( | |||
| SELECT count(id) | |||
| FROM pessoa_comunidade | |||
| WHERE pessoa_id = ? | |||
| AND comunidade_id = comunidade.id | |||
| ) seguindo, | |||
| ( | |||
| SELECT count(id) | |||
| FROM pessoa_comunidade | |||
| WHERE comunidade_id = comunidade.id | |||
| ) pessoas, | |||
| ( | |||
| SELECT count(id) | |||
| FROM publicacao | |||
| WHERE comunidade_id = comunidade.id | |||
| ) publicacoes | |||
| FROM comunidade | |||
| WHERE active = true | |||
| AND uid = ?::uuid | |||
| ORDER BY nome | |||
| `, userPessoa().getInt("id"), _req.getString("uid")) | |||
| const data = _val.map() | |||
| if (dbComunidade != null) { | |||
| data.set("uid", dbComunidade.getString("uid")) | |||
| .set("name", dbComunidade.getString("nome")) | |||
| .set("description", dbComunidade.getString("descricao")) | |||
| .set("following", dbComunidade.getInt("seguindo") > 0) | |||
| .set("people", dbComunidade.getInt("pessoas")) | |||
| .set("publications", dbComunidade.getInt("publicacoes")) | |||
| } | |||
| _out.json(data) | |||
| @ -0,0 +1,2 @@ | |||
| _out.json(_val.map().set("result", true)) | |||
| @ -1,23 +1,32 @@ | |||
| // _core : social/userPessoa | |||
| const dbComunidades = _db.query(` | |||
| SELECT | |||
| uid, | |||
| nome, | |||
| descricao, | |||
| imagem | |||
| imagem, | |||
| ( | |||
| SELECT count(id) | |||
| FROM pessoa_comunidade | |||
| WHERE pessoa_id = ? | |||
| AND comunidade_id = comunidade.id | |||
| ) seguindo | |||
| FROM comunidade | |||
| WHERE active = true | |||
| ORDER BY nome | |||
| `) | |||
| `, userPessoa().getInt("id")) | |||
| const data = _val.list() | |||
| for (const dbComunidade of dbComunidades) { | |||
| data.add( | |||
| _val.map() | |||
| .set("uid", dbComunidade.getString("uid")) | |||
| .set("name", dbComunidade.getString("nome")) | |||
| .set("description", dbComunidade.getString("descricao")) | |||
| .set("following", dbComunidade.getInt("seguindo") > 0) | |||
| ) | |||
| } | |||
| @ -0,0 +1,71 @@ | |||
| import React, { useEffect, useState} from 'react'; | |||
| import _service from '@netuno/service-client'; | |||
| import { useParams } from "react-router-dom"; | |||
| import { Button, Spin, Row, Col, notification } from 'antd'; | |||
| import { CheckCircleOutlined } from '@ant-design/icons'; | |||
| import "./index.less"; | |||
| export default ()=> { | |||
| const [data, setData] = useState(null); | |||
| const [following, setFollowing] = useState(false); | |||
| const { uid } = useParams(); | |||
| useEffect(()=> { | |||
| _service({ | |||
| method: 'GET', | |||
| url: "api/communities/detail", | |||
| data: { uid }, | |||
| success: (response) => { | |||
| setData(response.json); | |||
| setFollowing(response.json.following); | |||
| }, | |||
| fail: (e) => { | |||
| console.log("Service Error", e); | |||
| notification["error"]({ | |||
| message: 'Informações', | |||
| description: 'Não foi possível carregar a informação.', | |||
| }); | |||
| } | |||
| }); | |||
| }, []); | |||
| const onFollow = ()=> { | |||
| _service({ | |||
| method: 'PUT', | |||
| url: "api/communities/follow", | |||
| data: {uid: data.uid}, | |||
| success: (response) => { | |||
| setFollowing(response.json.result); | |||
| }, | |||
| fail: (e) => { | |||
| console.log("Service Error", e); | |||
| notification["error"]({ | |||
| message: 'Informações', | |||
| description: 'Não foi possível carregar a informação.', | |||
| }); | |||
| } | |||
| }); | |||
| }; | |||
| const servicePrefix = _service.config().prefix; | |||
| if (data == null) { | |||
| return <Spin />; | |||
| } | |||
| return ( | |||
| <div className="community"> | |||
| <div className="community__banner" style={{ backgroundImage: `url(${ servicePrefix }/api/communities/image?uid=${ data.uid })` }}> | |||
| <h1>{ data.name } { following ? <CheckCircleOutlined /> : <Button type="link" onClick={onFollow}>Seguir</Button> }</h1> | |||
| </div> | |||
| <Row> | |||
| <Col span={8}>Pessoas: {data.people}</Col> | |||
| <Col span={8}>Publicações: {data.publications}</Col> | |||
| <Col span={8}>{ following ? <><CheckCircleOutlined /> Seguindo</> : <Button type="link" onClick={onFollow}>Seguir</Button> }</Col> | |||
| </Row> | |||
| </div> | |||
| ); | |||
| }; | |||
| @ -0,0 +1,13 @@ | |||
| .community { | |||
| &__banner { | |||
| background-size: cover; | |||
| background-repeat: no-repeat; | |||
| background-position: 50% 50%; | |||
| height: 300px; | |||
| h1 { | |||
| background-color: rgba(0, 0, 0, 0.75); | |||
| padding: 10px; | |||
| } | |||
| } | |||
| } | |||