Skip to content

Commit 958d461

Browse files
committed
Quote Fetch: Provider changed
1 parent 8585477 commit 958d461

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

docs/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CDC Figma Plugin React Starter Kit
22

3-
A starter kit for building Figma plugins with React & TypeScript. Includes boilerplate code and essential config for quick Figma plugin development.
3+
A starter kit for building Figma plugins with React & TypeScript. Includes boilerplate code and essential config for quick Figma plugin development.
44

55

66
### Getting Started
@@ -59,7 +59,7 @@ Remember to add any new domains you want to make requests to in the `manifest.js
5959
import axiosClient from '../utils/axiosClient';
6060
..
6161
....
62-
const response = await axiosClient.get('https://dummyjson.com/quotes/random');
62+
const response = await axiosClient.get('https://zenquotes.io/api/random');
6363
const data = response.data;
6464
`````
6565

manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
],
1414
"networkAccess": {
1515
"allowedDomains": [
16-
"https://dummyjson.com",
16+
"https://api.allorigins.win",
17+
"https://zenquotes.io",
1718
"https://www.figma.com"
1819
]
1920
}

ui/app/Demo/AsyncFetchQuoteHttp.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
'use client';
2-
import React, { useState } from 'react';
1+
import { useState } from 'react';
32
import axiosClient from '../utils/axiosClient';
43

54
export default function AsyncFetchQuoteHttp({ sendToFigma }: { sendToFigma: (message: any) => void }) {
@@ -10,9 +9,13 @@ export default function AsyncFetchQuoteHttp({ sendToFigma }: { sendToFigma: (mes
109
const fetchQuote = async () => {
1110
setIsLoading(true);
1211
try {
13-
const response = await axiosClient.get('https://dummyjson.com/quotes/random');
14-
const data = response.data;
15-
const randomQuote = data.quote + ' - ' + data.author;
12+
const response = await axiosClient.get('https://api.allorigins.win/get?url=' + encodeURIComponent('https://zenquotes.io/api/random'));
13+
// PS:redirection URL was suggested for CORS issues by Claude 4
14+
// ZenQuotes decode:
15+
const data = response.data?.contents??{};
16+
const dataJson = JSON.parse(data)[0] ?? {};
17+
console.log('Fetched data:', dataJson);
18+
const randomQuote = dataJson.q + ' - ' + dataJson.a;
1619
setQuote(randomQuote);
1720
sendToFigma({ type: 'demo-insert-quote', quote: randomQuote });
1821
} catch (error) {
@@ -25,11 +28,11 @@ export default function AsyncFetchQuoteHttp({ sendToFigma }: { sendToFigma: (mes
2528
return (
2629
<div>
2730
<h3 className="text-md font-bold">Fetch quote via HTTP</h3>
28-
<p className="text-xs text-gray-500 pt-0 pb-2">Retrieves a random quote asynchronously from <a className='text-blue-400' rel="external nofollow noopener" href="https://dummyjson.com/quotes/" target="_blank">dummyjson.com</a> and inserts it into Figma</p>
31+
<p className="text-xs text-gray-500 pt-0 pb-2">Retrieves a random quote asynchronously from <a className='text-blue-400' rel="external nofollow noopener" href="https://zenquotes.io/" target="_blank">zenquotes.io</a> and inserts it into Figma</p>
2932
<button onClick={fetchQuote} type="button" disabled={isLoading} className={`text-sm text-white py-1 px-3 rounded-sm ${isLoading ? 'bg-gray-500' : 'bg-blue-500 hover:bg-blue-700'}`}>
3033
{isLoading ? 'Fetching...' : 'Fetch and insert'}
3134
</button>
32-
{ quote &&
35+
{quote &&
3336
<blockquote className="text-gray-500 mt-3 text-xs border-l-4 border-blue-500 pl-4 py-2 rounded-lg">{quote}</blockquote>
3437
}
3538
</div>

0 commit comments

Comments
 (0)