()
| 118 | } |
| 119 | |
| 120 | async function startUI() { |
| 121 | figma.showUI(__html__, { visible: false }); |
| 122 | figma.ui.onmessage = async (msg) => { |
| 123 | if (msg.type === "category") { |
| 124 | categories = msg.response.trivia_categories.map( |
| 125 | (c: { name: string; id: number }) => ({ name: c.name, data: c.id }) |
| 126 | ); |
| 127 | } else if (msg.type === "questions") { |
| 128 | const response = msg.response |
| 129 | const triviaResponse: TriviaResponse = { |
| 130 | responseCode: response.response_code, |
| 131 | results: response.results.map(r => ({ |
| 132 | category: r.category, |
| 133 | type: r.type, |
| 134 | difficulty: r.difficulty, |
| 135 | question: r.question, |
| 136 | correctAnswer: r.correct_answer, |
| 137 | incorrectAnswers: r.incorrect_answers |
| 138 | })) |
| 139 | } |
| 140 | displayQuestions(triviaResponse) |
| 141 | figma.closePlugin(); |
| 142 | } |
| 143 | }; |
| 144 | } |
| 145 | |
| 146 | function displayQuestions(triviaResponse: TriviaResponse) { |
| 147 | const frame = figma.createFrame() |
no test coverage detected