기본 콘텐츠로 건너뛰기

vulcanJS - 7. Posts 쓰기

이번엔 아주 간단합니다.
왜냐면 Posts 쓰기를 할 것이고 우리는 SmartForms를 이용해서 끝낼려고 하거든요.

Component를 또 만듭시다.
이름은 PostsNewComponent가 좋겠군요.
$ vulcan g component
? Package name spectrum-simplebb
? Component name PostsNewComponent
? Component type Class Component
? Register component Yes
   create packages/spectrum-simplebb/lib/components/PostsNewComponent.jsx
 conflict packages/spectrum-simplebb/lib/components/index.js
? Overwrite packages/spectrum-simplebb/lib/components/index.js? overwrite
    force packages/spectrum-simplebb/lib/components/index.js
이제 다 할 줄 아시죠?
vulcan g component 를 써서 진행합니다.
HomeComponent.jsx 에도 추가해야겠네요.
import React, { Component } from 'react';
import { registerComponent, Components } from 'meteor/vulcan:core';
class HomeComponent extends Component {
  render () {
    return (
      <div>
        Find me at packages/spectrum-simplebb/lib/components/HomeComponent.jsx
        <Components.PostsListComponent />
        <Components.PostsNewComponent />
      </div>
    );
  }
}
registerComponent('HomeComponent', HomeComponent);
export default HomeComponent;
이렇게 <Components.PostsNewComponent /> 한 줄 넣어줍니다.
Find me at packages/spectrum-simplebb/lib/components/HomeComponent.jsx
first thing
Find me at packages/spectrum-simplebb/lib/components/PostsNewComponent.jsx
브라우저에서 보면 PostsNewComponent.jsx가 잘 등록이 되있네요.
이제 Posts 입력 Form을 넣어봅시다.
http://docs.vulcanjs.org/forms.html 내용을 보면서 package.js 에 vulcan:forms를 추가합니다.
플러그인처럼 필요한 기능을 넣으면 되어서 편리합니다.
Package.describe({
  name: 'spectrum:simplebb',
});
Package.onUse((api) => {
  api.use([
    'vulcan:core',
    'vulcan:forms'
  ]);
  api.mainModule('lib/server/main.js', 'server');
  api.mainModule('lib/client/main.js', 'client');
});
가끔 package가 추가 안되는 경우가 있는데 meteor add vulcan:forms 후 meteor remove vulcan:forms 해서 넣다 빼 봅시다.
아무래도 버그(https://github.com/meteor/meteor/issues/7721)인 것 같습니다. 부디 다음버전에서 개선이 되길.


먼저 import Posts from  "../modules/posts/collection.js" 를 가져오고 vulcan의 Components 객체도 가져옵니다.
        <Components.SmartForm collection={Posts} />
한 줄만 넣어봅시다. PostsNewComponents.jsx는 이렇게 되겠지요.
import React, { Component } from 'react';
import { registerComponent, Components } from 'meteor/vulcan:core';
import Posts from  "../modules/posts/collection.js"
class PostsNewComponent extends Component {
  render () {
    return (
      <div>
        <Components.SmartForm collection={Posts} />
      </div>
    );
  }
}
registerComponent('PostsNewComponent', PostsNewComponent);
export default PostsNewComponent;
이제 브라우저 화면을 봅시다.
오오. Title과 Body가 생겼고 입력창도 보입니다.
뭔가 넣어봅시다.

이거슨 매직
입력하고 submit 누르면...?

!?!!!

들어갔습니다!
아니 뭐 이렇게 간단해도 되는 건가 싶은데 내부는 꽤 복잡합니다.
Collection2 + autoform + graphQL + react 까지 모두 합쳐서 이런 결과를 잘도 만들었네요.

해놓고 보니 다 좋은데 Body는 여러줄을 입력받고 싶습니다.
http://docs.vulcanjs.org/forms.html 내용을 읽어보니 
Support for basic form controls (input, textarea, radio, etc.).
이런 내용이 있습니다.
예제를 보니 schema에서 control 이라는 속성을 추가할 수 있나보네요.
./lib/modules/posts/schema.js 를 열어봅시다.
중간쯤 (아마 31라인 근처)
    title : {
   label: 'Title' ,
  type: String,
  optional: false,
  viewableBy: ['guests'],
  insertableBy: ['members'],
  editableBy: ['members'],
},

  
    body : {
   label: 'Body' ,
  type: String,
  optional: true,
  viewableBy: ['guests'],
  insertableBy: ['members'],
  editableBy: ['members'],
},
title과 body 속성을 이렇게 삐뚤삐뚤하게 자동 생성을 해놓았군요.
  control: 'text' 와 control: 'textarea' 를 각각 추가해봅시다.
schema.js 전체는 이렇겠지요.
const schema = {
  // default properties
  _id: {
    type: String,
    optional: true,
    viewableBy: ['guests'],
  },
  createdAt: {
    type: Date,
    optional: true,
    viewableBy: ['guests'],
    onInsert: (document, currentUser) => {
      return new Date();
    }
  },
  // userId: {
  //   type: String,
  //   optional: true,
  //   viewableBy: ['guests'],
  //   resolveAs: {
  //     fieldName: 'user',
  //     type: 'User',
  //     resolver: (movie, args, context) => {
  //       return context.Users.findOne({ _id: movie.userId }, { fields: context.Users.getViewableFields(context.currentUser, context.Users) });
  //     },
  //     addOriginalField: true
  //   }
  // },
 
    title : {
   label: 'Title' ,
  type: String,
  control: 'text',
  optional: false,
  viewableBy: ['guests'],
  insertableBy: ['members'],
  editableBy: ['members'],
},
 
    body : {
   label: 'Body' ,
  type: String,
  control: 'textarea',
  optional: true,
  viewableBy: ['guests'],
  insertableBy: ['members'],
  editableBy: ['members'],
},
 
};
export default schema;
다시 화면을 봅니다.
오오 TextArea가 나왔군요.

멀티라인!

멀티 라인을 입력할 수 있네요.
내용이 잘 들어갔는지 graphiQL(http://localhost:3000/graphiql)에서 한번 확인해볼까요? 절대 Component에서 화면에 보이게 구현하는게 귀찮아서 그러는게 아닙니다. 연습연습~ 자동완성으로 착착 입력합시다.
{
  PostsList(terms:{}) {
    _id
    createdAt
    title
    body
  }
}
로 검증해 봅니다.

\n로 구분한 멀티라인까지 잘 들어간 것을 확인할 수 있습니다.
꽤 편리하지요?
거의 다 왔습니다. 세부 조회, 수정이랑 삭제 정도만 하면 한 바퀴 다 돌아볼 것 같습니다.
용기를 잃지말고 계속 Meteor 고고! Vulcan 고고!

댓글

이 블로그의 인기 게시물

세상 간단한 https(+secured websocket): Caddy

nginx, apache2 같은 걸로 매번 certbot 연동을 통해 https 하는게 지겨워서 알아보니 Caddy라는게 있더라. 설치법은 강하게 크기 위해 알아서 해본다. # cat /etc/caddy/Caddyfile your.shitty.site:8123 {   proxy / localhost:9123 {     websocket     transparent   } } 이건 외부에서 8123으로 들어오는 걸 내부적으로 9123로 맞춰서 https 맞춰주는 reverse proxy. 만일 port를 생략하면 # cat /etc/caddy/Caddyfile your.shitty.site {   proxy / localhost:9123 {     websocket     transparent   } } 기본포트인 443으로 되어 https://your.shitty.site 로 접속이 된다. 요새 말썽이던 cloudflare 버리고 netlify domain이랑 caddy를 쓰니까 앓던 이가 빠진 느낌. 이 조합은 당분간 계속 써야겠다 싶다.

LG G Pro 2 Custom Rom +Rooting 기록

선 루팅 https://forum.xda-developers.com/lg-g3/general/guide-root-lg-firmwares-kitkat-lollipop-t3056951 1.2버전 스크립트 모드로. echo Looking for LG serial port.. echo. adb.exe wait-for-device 여기에서 정체 상태여서 강제로 adb kill-server 했더니 알아서 재부팅하심. 폰에선 "펌웨어 업데이트"화면이 나오고 Phone found at COM5! Rooting phone.. If you don't see the SuperSu installer script runs within about a minute, then the root failed. Author : blog.lvu.kr SPECIAL COMMAND : ENTER, LEAVE ## 이런 상황이 됨. #이 느린 속도로 하나씩 증가하고 있음. 한 시간 기다려도 성과없음. 뭐 몇번해봐도 안되고 결국 불안하긴 하지만 kingroot.net  로 설치 롤리팝이니까  https://drive.google.com/file/d/0B4kfGU1z_PClQ3AyM2lKOGR1S3M/view  이걸 받아서 압축 풀기. d838recovery.bat 만 있어서 당황스럽긴한데 실행하고 1번 하니까 리커버리 모드 진입까진 잘 되는 듯. adb sideload 라는게 있어서 해봄. Advance에서 adb sideload 선택하고 USB연결한 PC에서 adb sideload RR-N-v5.8.5-20171010-d838-Final.zip 하니까 착착 잘 진행됨. 이제 흉측한 U+LTE 가 없어짐. ㅇㅋ 군더더기 없고 깔끔한데 남은 건 gapps 를 설치해야함. http://opengapps.org/  를 권해줘서 갔는데 지옥 느림. ARM + 7.1 + stock 이 기본이...

Google Daydream 소감

드디어 V30 사은품인 Daydream이 왔다. 낭랑한 벨과 함께 무심한 듯 시크하게 툭 던지고 가시는 택배느님. 수령까지 두달 걸렸다. 눈을 뜨고 꿈꿔 보세요. 여기가 눈감으면 코베어 간다는 서울인가? 주황색면으로 열면 된다. 컨트롤러의 만듦새는 아주 좋다. 기존에 나와있는 사진엔 가로 머리끈만 있어서 똥머리한 언니들도 막 쓰고 플레이하고 그랬는데 실제로 보니 이중 끈이었다. 보통 돌아다니는 착샷 Daydream 설치 - 실행 - 폰 장착 - 컨트롤러 페어링 - VR진입까지 과정을 쉽게 하려고한 노력이 보였음. NFC로 데이드림뷰어에 폰을 장착하면 자동으로 인식하여 데이드림 앱이 실행되는 경험은 꽤 괜찮았음. 컨트롤러는 크기, 그립감 면에서 매우 훌륭하고 인식률, 반응속도 모두 만족스러움. 홈버튼으로 시선을 재 조정하는 발상은 좋은데 왼쪽 오른쪽이 앱마다 조금 혼란스럽고 상하방향 캘리브레이션은 안된다. 이 부분에서 좌절했다. 누워서 넷플릭스를 보는 건 다른 방법을 찾아보아야한다는 소리. 알고보니 이런 건 Youtube이나 Netflix, Skybox player 등등에서 테스트해본 결과 자체 앱에서 지원하고 있다. Netflix는 void theater라는 것이 있는데  <출처:  https://元ボクサーの一念発起.com/2018/05/10/oculus-go/ > Netflix app에서 요렇게 눈송이 같이 생긴 아이콘을 컨트롤러로 찍고 들어가면 화면만 덩그러니 나오고 스티어링휠(자동차 핸들) 모양 아이콘을 선택하고 누으면 자연스럽게 조정이 되었다. Youtube나 Skybox앱의 경우 아예 컨트롤러에서 꾹 누르고 화면 이동하는게 가능해서 편리. 게임은 이것저것 해봤는데 Rez Infinite이 최고. 아니 이건 그냥 전 VR 기기를 통틀어서 Rez Infinite이 최고가 아닐까 싶음;;; 결론,  1. 누워서 보기 잘된다. 2. ...