Media.js 1007 Bytes
Newer Older
Giang Tran committed
1 2
import React, {Component, useEffect, useState} from 'react';
import {View, Text, Platform, Alert} from 'react-native';
Giang Tran committed
3
import I18n from '../../../helper/i18/i18n';
Giang Tran committed
4 5 6

import MediaView from './MediaView';
import {getListMedia} from '../../../apis/Functions/NewFeed';
Giang Tran committed
7
import {showAlert, TYPE} from '../../../components/DropdownAlert';
Giang Tran committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

const Media = (props) => {
  const [data, setData] = useState([]);
  const [mediaHot, setMediaHot] = useState();

  useEffect(() => {
    getData();
  }, []);

  const getData = async () => {
    const res = await getListMedia({
      keyword: '',
      topic_id: '',
      platform: Platform.OS,
    });
    if (res.data.code == 200 && res.data.data) {
      if (res.data.data[0] && res.data.data[0].data[0])
        setMediaHot(res.data.data[0].data[0]);
      setData(res.data.data);
    } else {
Giang Tran committed
28
      showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('Can_not_get_data'));
Giang Tran committed
29 30 31 32 33 34 35
    }
  };

  return <MediaView data={data} mediaHot={mediaHot} />;
};

export default Media;