Created
October 13, 2021 14:01
-
-
Save albertogiunta/1ce8165a9e9463328021c5fa3deba239 to your computer and use it in GitHub Desktop.
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
import { searchWeatherLocation } from "utils/sourceSuggestionFetchers"; | |
import { v4 as uuidv4 } from "uuid"; | |
/* | |
Generic props with sensible defaults, they should stay in their own file | |
The input params could be composed even more, by creating a couple more | |
that capture the various possible sensible configurations | |
*/ | |
interface ISourceProps { | |
id: string; | |
} | |
function sourceProps(): ISourceProps { | |
return { | |
id: uuidv4(), | |
}; | |
} | |
interface IEditorProps { | |
images_style?: string; | |
post_body?: string; | |
style?: string; | |
num_posts?: number; | |
show_images?: boolean; | |
columns?: number; | |
width?: string; | |
} | |
function editorProps({ | |
images_style = "full", | |
post_body = "excerpt", | |
style = "card", | |
num_posts = 4, | |
show_images = true, | |
columns = 1, | |
width = "wide", | |
}: IEditorProps = {}): any { | |
return { | |
images_style, | |
post_body, | |
style, | |
num_posts, | |
show_images, | |
columns, | |
width, | |
}; | |
} | |
interface IModalProps { | |
openEditor?: boolean; | |
shareable?: boolean; | |
isValid?: (source: any) => boolean; | |
inlineFetcher?: (arg0: any, arg1: any) => void; | |
inlinePlaceholders?: string[]; | |
} | |
function modalProps({ | |
openEditor = true, | |
shareable = false, | |
isValid = (_) => true, | |
inlineFetcher = (_, __) => undefined, | |
inlinePlaceholders = [], | |
}: IModalProps = {}): any { | |
return { | |
openEditor, | |
shareable, | |
isValid, | |
inlineSearch: { | |
fetcher: inlineFetcher, | |
placeholders: inlinePlaceholders, | |
}, | |
}; | |
} | |
interface ISuggestionProps { | |
type: string; | |
nameForIcon: string; | |
color: string; | |
synonyms: string; | |
} | |
/* | |
Objects to be used in the modal as blocks or sources. | |
They should created for all the sources, each in its own file. | |
*/ | |
const weatherSuggestionProps: ISuggestionProps = { | |
type: "weather", | |
nameForIcon: "weather", | |
color: "#67379", | |
synonyms: "weather meteo", | |
// TODO: computed for glyph and thumb. | |
}; | |
const weatherBlock = { | |
...weatherSuggestionProps, | |
...modalProps({ inlineFetcher: searchWeatherLocation, inlinePlaceholders: ["Search city..."] }), | |
}; | |
interface IWeatherSourceProps { | |
key: string | null; | |
name: string; | |
} | |
/* In its default form it's a block. If parameters are given it becomes a source */ | |
function weatherSource({ key, name }: IWeatherSourceProps = { key: null, name: "" }) { | |
return { | |
...weatherBlock, | |
...sourceProps(), | |
...editorProps(), | |
location_key: key, | |
location_name: name, | |
}; | |
} | |
// example of hardcoded source. These would replace the hardcoded ones in sources.js (e.g. "Daily Quote", "Changelog") | |
const milanWeatherSource = weatherSource({ key: "asdf", name: "Milan, Italy" }); | |
export { weatherBlock, weatherSource }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
questo andava tolto sorry 🙏
quindi la source diventa: