Refactoring: split files into components (not working, broken state)
[vchess.git] / public / javascripts / components / problemPreview.js
diff --git a/public/javascripts/components/problemPreview.js b/public/javascripts/components/problemPreview.js
new file mode 100644 (file)
index 0000000..5336503
--- /dev/null
@@ -0,0 +1,25 @@
+// Preview a problem on variant page
+Vue.component('my-problem-preview', {
+       props: ['prob'],
+       template: `
+               <div class="row problem">
+                       <div class="col-sm-12 col-md-6 diagram"
+                               v-html="getDiagram(prob.fen)">
+                       </div>
+                       <div class="col-sm-12 col-md-6">
+                               <p v-html="prob.instructions"></p>
+                               <p v-html="prob.solution"></p>
+                       </div>
+               </div>
+       `,
+       methods: {
+               getDiagram: function(fen) {
+                       const fenParsed = V.ParseFen(fen);
+                       return getDiagram({
+                               position: fenParsed.position,
+                               turn: fenParsed.turn,
+                               // No need for flags here
+                       });
+               },
+       },
+})