clubzella-comic-test-v1
Version:
A clubzella widget component library for React Native.
196 lines (193 loc) • 9.71 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_native_1 = require("react-native");
var react_1 = __importStar(require("react"));
var Ionicons_1 = __importDefault(require("@expo/vector-icons/Ionicons"));
var AntDesign_1 = __importDefault(require("@expo/vector-icons/AntDesign"));
var EpisodesPanel_1 = __importDefault(require("./EpisodesPanel"));
var AllComics_1 = __importDefault(require("./AllComics"));
var API_URL_1 = require("./constants/API_URL");
var _a = react_native_1.Dimensions.get("window"), height = _a.height, width = _a.width;
var ComicsPanel = function (_a) {
var _b = _a.visible, visible = _b === void 0 ? false : _b, setOpenComicsPanel = _a.setOpenComicsPanel, apiKey = _a.apiKey;
var _c = (0, react_1.useState)(false), expand = _c[0], setExpand = _c[1];
var _d = (0, react_1.useState)(false), openEpisodesPanel = _d[0], setOpenEpisodesPanel = _d[1];
var _e = (0, react_1.useState)(), comic = _e[0], setComic = _e[1];
var handleSetComic = function (comic) {
setComic(comic);
};
var _f = (0, react_1.useState)(true), isLoading = _f[0], setIsLoading = _f[1];
var _g = (0, react_1.useState)([]), comics = _g[0], setComics = _g[1];
(0, react_1.useEffect)(function () {
var response = fetch("".concat(API_URL_1.API_URL, "/comics"), {
headers: { "merchant-x-secret": "".concat(apiKey) },
});
response.then(function (data) { return __awaiter(void 0, void 0, void 0, function () {
var text, comics_, error_1;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, 3, 4]);
return [4 /*yield*/, data.text()];
case 1:
text = _b.sent();
if (text) {
comics_ = (_a = JSON.parse(text)) === null || _a === void 0 ? void 0 : _a.data;
if (comics_) {
setComics(comics_);
}
}
return [3 /*break*/, 4];
case 2:
error_1 = _b.sent();
console.log(error_1);
return [3 /*break*/, 4];
case 3:
setIsLoading(false);
return [7 /*endfinally*/];
case 4: return [2 /*return*/];
}
});
}); });
}, []);
return (<>
<react_native_1.View style={[
{
zIndex: 1100,
borderRadius: 15,
justifyContent: "center",
alignItems: "center",
position: "absolute",
bottom: 20,
right: 15,
width: width - 30,
backgroundColor: "#fff",
height: expand ? height / 1.5 : 140,
elevation: 4,
},
]}>
<react_native_1.Animated.View>
<react_native_1.View style={{
minHeight: 35,
width: "100%",
backgroundColor: "#393535",
borderTopStartRadius: 15,
borderTopEndRadius: 15,
padding: 11,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
gap: 10,
}}>
<react_native_1.Text style={{
color: "#F5F5F5",
fontSize: 25,
lineHeight: 25,
fontFamily: "MamaKilo",
textTransform: "uppercase",
}}>
Orisha warz
</react_native_1.Text>
<react_native_1.TouchableOpacity activeOpacity={0.6} onPress={function () { return setExpand(!expand); }}>
<Ionicons_1.default name="expand" size={24} color="#fff"/>
</react_native_1.TouchableOpacity>
<react_native_1.View style={{
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
gap: 10,
}}>
<react_native_1.TouchableOpacity activeOpacity={0.6} onPress={function () { return setOpenComicsPanel(!visible); }}>
<AntDesign_1.default name="close" size={24} color="#FF4D52"/>
</react_native_1.TouchableOpacity>
</react_native_1.View>
</react_native_1.View>
</react_native_1.Animated.View>
<react_native_1.ScrollView style={{ height: "100%", width: "100%" }}>
<react_native_1.View style={{ padding: 12, gap: 16 }}>
{isLoading ? (<react_native_1.View style={{
height: expand ? 500 : "auto",
justifyContent: "center",
}}>
<react_native_1.ActivityIndicator size={"large"}/>
</react_native_1.View>) : (<AllComics_1.default comics={comics} setOpenEpisodesPanel={setOpenEpisodesPanel} openEpisodesPanel={openEpisodesPanel} handleSetComic={handleSetComic}/>)}
</react_native_1.View>
</react_native_1.ScrollView>
</react_native_1.View>
{openEpisodesPanel && (<EpisodesPanel_1.default title={(comic === null || comic === void 0 ? void 0 : comic.title) || ""} visible={openEpisodesPanel} setOpenEpisodesPanel={setOpenEpisodesPanel} series_id={(comic === null || comic === void 0 ? void 0 : comic.id) || 0} apiKey={apiKey}/>)}
</>);
};
exports.default = ComicsPanel;