diff --git a/src/apps/gif-app/composer/app.tsx b/src/apps/gif-app/composer/app.tsx index ae02cbb..79b8baa 100644 --- a/src/apps/gif-app/composer/app.tsx +++ b/src/apps/gif-app/composer/app.tsx @@ -1,13 +1,12 @@ import React, { FC, useState, useEffect } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faSearch } from '@fortawesome/free-solid-svg-icons' -import { Communicator, Theme } from '../../../communicator' +import { faSearch, faSpinner } from '@fortawesome/free-solid-svg-icons' +import { Communicator, Theme, InstallationSettings } from '../../../communicator' import Gif from './gif' import { GiphyGif } from '../../../types' const giphyIcon = require('./giphy.png') import '../../../styles/default.css' -import '../../../styles/spinner.css' type APIResponse = GiphyGif[] @@ -35,6 +34,7 @@ const App: FC = ({ communicator }) => { const [posting, setPosting] = useState(false) const [searching, setSearching] = useState(false) const [search, setSearch] = useState('') + const [settings, setSettings] = useState({}) const searchD = useDebounce(search) const [gifs, setGifs] = useState([]) const [selected, setSelected] = useState('') @@ -55,10 +55,14 @@ const App: FC = ({ communicator }) => { const init = async () => { try { const content = await communicator.init() - if (content!.theme) setTheme(content!.theme) - if (content && content.parent && content.parent.data && content.parent.data.search) { - setSearch(content.parent.data.search) + if (content) { + if (content.settings) setSettings(content.settings) + if (content.theme) setTheme(content.theme) + + if (content.parent && content.parent.data && content.parent.data.search) { + setSearch(content.parent.data.search) + } } await communicator.setHeight(1000) @@ -79,9 +83,26 @@ const App: FC = ({ communicator }) => { const doSearch = async () => { try { setSearching(true) + const response = await fetch(`/api/gifs/search?q=${search}`) setGifs(await response.json() as APIResponse) - } catch (err) {} + + const previousSearches: string[] = settings.searches ?? [] + const searches = [ + search, + ...previousSearches.slice(0, 9), + ] + + const newSettings = { + ...settings, + searches, + } + + await communicator.saveSettings(newSettings) + setSettings(newSettings) + } catch (err) { + console.error(err) + } setSearching(false) } @@ -124,6 +145,11 @@ const App: FC = ({ communicator }) => { setPosting(false) } + const getPlaceholder = () => { + const searches = settings.searches as string[] ?? [] + return searches[0] ? `Last Search: ${searches[0]}` : 'Search' + } + return (
@@ -135,7 +161,7 @@ const App: FC = ({ communicator }) => { handleSearchChange(e.target.value)} />
@@ -153,7 +179,7 @@ const App: FC = ({ communicator }) => {
diff --git a/src/apps/text-app/composer/app.tsx b/src/apps/text-app/composer/app.tsx index fcd6705..f9823b5 100644 --- a/src/apps/text-app/composer/app.tsx +++ b/src/apps/text-app/composer/app.tsx @@ -1,12 +1,11 @@ import React, { FC, useState, useEffect } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faShieldAlt } from '@fortawesome/free-solid-svg-icons' +import { faShieldAlt, faSpinner } from '@fortawesome/free-solid-svg-icons' import { Communicator, Post, Theme } from '../../../communicator' import '../../../styles/default.css' -import '../../../styles/spinner.css' -const promts = [ +const prompts = [ "What's going on?", 'What it do?', "What's happening?", @@ -79,7 +78,7 @@ const App: FC = ({ communicator }) => {