Skip to content

Instantly share code, notes, and snippets.

@mrsoftware
Last active July 7, 2019 13:35
Show Gist options
  • Save mrsoftware/91b15ed511c434506d09d05e14d3a326 to your computer and use it in GitHub Desktop.
Save mrsoftware/91b15ed511c434506d09d05e14d3a326 to your computer and use it in GitHub Desktop.
import types from "./App/components/Post/types";
const schema = [
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "video,image,text", model: 'rec', item: {} },
{ type: "video,image,text", model: 'rec', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "video,image,text", model: 'big', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "video,image,text", model: 'big', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
]
// text: data.media === null || [];
// image: data.media[0].type === 'image';
// video: data.media[0].type === 'video';
type datas = [
{
id: string,
user: object,
title: string,
content: string,
media: [
{
id: string,
type: string,
width: number,
height: number,
small: string | null,
medium: string | null,
large: string | null,
thumbnail: string | null,
video: string | null,
gif: string | null,
view_count: number,
}
],
}
]
const newData = [];
loop(schema as sch, index) {
types = sch.type.split(',');
loop(datas as data, dataIndex) {
const dataType = getType(data);
loop(types as type, typeIndex) {
if(type === dataType) {
handleData(data, index, dataIndex)
break;
}
}
}
}
const handleData = (data, index, dataIndex) => {
schema[index].item = data;
delete datas[dataIndex];
// remove data from datas
}
const getType = (data) => {
if (data.media === null || data.media === []) {
return 'text';
} else if (data.media[0].type === 'video') {
return 'video';
} else {
return 'image';
}
// image: data.media[0].type === 'image';
// video: data.media[0].type === 'video';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment