clubzella-comic-test-v1
Version:
A clubzella widget component library for React Native.
239 lines (237 loc) • 11.2 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 SimpleLineIcons_1 = __importDefault(require("@expo/vector-icons/SimpleLineIcons"));
var API_URL_1 = require("./constants/API_URL");
var react_native_pdf_1 = __importDefault(require("react-native-pdf"));
var _a = react_native_1.Dimensions.get("screen"), height = _a.height, width = _a.width;
var InComicsPanel = function (_a) {
var _b;
var _c = _a.visible, visible = _c === void 0 ? false : _c, setOpenInComicsPanel = _a.setOpenInComicsPanel, title = _a.title, episode_id = _a.episode_id, series_id = _a.series_id, apiKey = _a.apiKey;
var _d = (0, react_1.useState)(true), expand = _d[0], setExpand = _d[1];
var _e = (0, react_1.useState)(true), isLoading = _e[0], setIsLoading = _e[1];
var _f = (0, react_1.useState)(), episode = _f[0], setEpisode = _f[1];
(0, react_1.useEffect)(function () {
var response = fetch("".concat(API_URL_1.API_URL, "/comics/").concat(series_id, "/episodes/").concat(episode_id), {
headers: { "merchant-x-secret": "".concat(apiKey) },
});
response.then(function (data) { return __awaiter(void 0, void 0, void 0, function () {
var text, episode_, 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) {
episode_ = (_a = JSON.parse(text)) === null || _a === void 0 ? void 0 : _a.data;
// console.log(episode_)
if (episode_) {
setEpisode(episode_);
}
}
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,
// height: 140,
backgroundColor: "#fff",
height: expand ? height / 1.36 : 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",
}}>
Issue #{episode === null || episode === void 0 ? void 0 : episode.episode_number}
</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 setOpenInComicsPanel(!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.View style={{ height: "100%", width: "100%" }}>
<react_native_1.TouchableOpacity style={{
padding: 10,
paddingBottom: 12,
flexDirection: "row",
gap: 10,
alignItems: "center",
}} onPress={function () { return setOpenInComicsPanel(!visible); }}>
<SimpleLineIcons_1.default name="arrow-left" size={18} color="black"/>
<react_native_1.Text>Back to episodes</react_native_1.Text>
</react_native_1.TouchableOpacity>
{/* <Image source={comics} style={{ width: "100%", height: 550 }} /> */}
{isLoading ? (<react_native_1.View style={{
height: expand ? 500 : "auto",
justifyContent: "center",
}}>
<react_native_1.ActivityIndicator size={"large"}/>
</react_native_1.View>) : (<>
<react_native_pdf_1.default trustAllCerts={false} source={{
uri: ((_b = episode === null || episode === void 0 ? void 0 : episode.episode_file) === null || _b === void 0 ? void 0 : _b.media_url) || "",
cache: true,
}} onLoadComplete={function (numberOfPages, filePath) {
// console.log(`Number of pages: ${numberOfPages}`)
setIsLoading(false);
}} onPageChanged={function (page, numberOfPages) {
// console.log(`Current page: ${page}`)
}} onError={function (error) {
// console.log(error)
}} onPressLink={function (uri) {
// console.log(`Link pressed: ${uri}`)
}} style={styles.pdf} onLoadProgress={function (num) {
// setIsLoading(true)
// console.log(num)
}}/>
{/* <WebView
source={{
uri: `https://docs.google.com/gview?embedded=true&url=${
episode?.episode_file?.media_url || ""
}`,
}}
style={styles.pdf}
scalesPageToFit={true}
/> */}
</>)}
</react_native_1.View>
</react_native_1.View>);
};
var styles = react_native_1.StyleSheet.create({
container: {
flex: 1,
justifyContent: "flex-start",
alignItems: "center",
marginTop: 25,
},
pdf: {
height: "90%",
width: "100%",
borderRadius: 10,
// flex: 1,
},
});
exports.default = InComicsPanel;