-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add html elements for icon search * Add css class for icon search button * Add css class to select icon results * Add function to request flaticon api * Display preview of flaticon request * Add advice for debugging to README * Add icon result filter * Add filter parameters to freepik api request * Add object with id for freepik api response * Add function to get download path of clicked icon * Add function to download clicked icon * Add function to retrieve base64 string of clicked icon * Add function to insert icon to slide * Move icon download functions to separate file * Refactor base64 image insertion function * Refactor method name for adding icon previews * Extract methods for icon search integration * Display icon previews in dropdown * pair programming * Refactor variable and element names --------- Co-authored-by: Kyrylo Zakurdaiev <[email protected]>
- Loading branch information
1 parent
379091c
commit d5d9f5a
Showing
6 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { FetchIconResponse } from "./types"; | ||
|
||
export async function fetchIcons(searchTerm: string): Promise<Array<FetchIconResponse>> { | ||
const url = `https://hammerhead-app-fj5ps.ondigitalocean.app/icons?term=${searchTerm}&family-id=300&filters[shape]=outline&filters[color]=solid-black&filters[free_svg]=premium`; | ||
const requestHeaders = new Headers(); | ||
requestHeaders.append("X-Freepik-API-Key", "FPSX6fb1f23cbea7497387b5e5b8eb8943de"); | ||
const requestOptions = { | ||
method: "GET", | ||
headers: requestHeaders, | ||
}; | ||
|
||
try { | ||
const result = await fetch(url, requestOptions); | ||
const response = await result.json(); | ||
return response.data | ||
.filter((obj) => obj.author.name === "Smashicons" && obj.family.name === "Basic Miscellany Lineal") | ||
.map((obj) => ({ | ||
id: obj.id.toString(), | ||
url: obj.thumbnails[0].url, | ||
})) | ||
.slice(0, 50); | ||
} catch (e) { | ||
throw new Error("Error fetching icons: " + e); | ||
} | ||
} | ||
|
||
export async function getDownloadPathForIconWith(id: string) { | ||
const url = `https://hammerhead-app-fj5ps.ondigitalocean.app/icons/${id}/download?format=png`; | ||
const requestHeaders = new Headers(); | ||
requestHeaders.append("X-Freepik-API-Key", "FPSX6fb1f23cbea7497387b5e5b8eb8943de"); | ||
const requestOptions = { | ||
method: "GET", | ||
headers: requestHeaders, | ||
}; | ||
|
||
try { | ||
const result = await fetch(url, requestOptions); | ||
const response = await result.json(); | ||
return response.data.url; | ||
} catch (e) { | ||
throw new Error("Error getting download url: " + e); | ||
} | ||
} | ||
|
||
export async function downloadIconWith(url: string) { | ||
const requestOptions = { | ||
method: "GET", | ||
}; | ||
|
||
try { | ||
return await fetch(url, requestOptions); | ||
} catch (e) { | ||
throw new Error("Error downloading icon: " + e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type FetchIconResponse = { | ||
id: string; | ||
url: string; | ||
}; |