This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.useReturn
hook implementation for new frame
- Loading branch information
1 parent
a540f27
commit f2a44e8
Showing
10 changed files
with
261 additions
and
128 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useRef } from "react"; | ||
import { useEasybase } from "easybase-react"; | ||
|
||
const CardElement = ({ rating, picture, app_name, hq, latest_release, _key }: any) => { | ||
|
||
const inputEl = useRef<HTMLInputElement>(null); | ||
|
||
const { db } = useEasybase(); | ||
|
||
const onRatingChange = (change: number) => { | ||
db().set({ 'rating': rating + change }).where({ _key }).all() | ||
} | ||
|
||
const onDelete = () => { | ||
db().delete().where({ _key }).one(); | ||
} | ||
|
||
return ( | ||
<div className="card-root"> | ||
<div className="card-delete-button" onClick={onDelete}></div> | ||
<img src={picture} className="card-image" alt="" /> | ||
<input ref={inputEl} type='file' hidden accept="image/*,video/*" /> | ||
<p className="mp-0" style={{ textAlign: 'center' }}>{latest_release ? latest_release.slice(0, 10) : ""}</p> | ||
<div className="p-4" style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}> | ||
<h5>{app_name}</h5> | ||
<em>{hq}</em> | ||
</div> | ||
<div style={{ display: "flex", alignItems: "center" }}> | ||
<button className="btn orange" onClick={_ => onRatingChange(-1)}><span>-</span></button> | ||
<p>{rating}</p> | ||
<button className="btn orange" onClick={_ => onRatingChange(1)}><span>+</span></button> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default CardElement; |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { useEasybase } from 'easybase-react'; | ||
import CardElement from "./DbCardElement"; | ||
|
||
const UseReturnExample = () => { | ||
|
||
const [tableLength, setTableLength] = useState(0); | ||
const [frameLength, setFrameLength] = useState(10); | ||
const [frameOffset, setFrameOffset] = useState(0); | ||
const [ratingState, setRatingState] = useState(50); | ||
|
||
const { | ||
db, | ||
useReturn, | ||
fullTableSize, | ||
e | ||
} = useEasybase(); | ||
|
||
const { frame, manualFetch, unsubscribe, loading } = useReturn(() => db().return().where(e.lt('rating', ratingState)).limit(frameLength).offset(frameOffset), [ frameLength, frameOffset, ratingState ]); | ||
|
||
useEffect(() => { | ||
async function mounted() { | ||
setTableLength(await fullTableSize()) | ||
} | ||
mounted(); | ||
}, []) | ||
|
||
|
||
const onAddPage = async () => { | ||
await db().insert({ rating: 68, "app name": "Inserted App", _position: 0 }).all(); | ||
} | ||
|
||
const changePage = async (change: number) => { | ||
setFrameOffset(prev => Math.abs(prev + change)); | ||
} | ||
|
||
const getFirstRecord = async () => { | ||
console.log(await db().return("app_name").where({ _position: 0 }).one()); | ||
console.log(await db().return("app_name").where({ _position: 0 }).all()); | ||
console.log(await db().return().where({ _position: 0 }).one()); | ||
console.log(await db().return().where({ _position: 0 }).all()); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div style={{ display: "flex", alignItems: "center" }}> | ||
<div className="m-4"> | ||
<button className="btn green" onClick={onAddPage}><span>Add<br />Card</span></button> | ||
</div> | ||
{loading ? <div className="loader"></div> : frame.map((ele, index) => <CardElement {...ele} index={index} key={index} />)} | ||
</div> | ||
<div className="button-row"> | ||
<div className="d-flex align-items-center"> | ||
<button className="btn green" onClick={() => changePage(-10)}><span>Prev</span></button> | ||
<p className="m-4">{frameOffset} - {frameOffset + Number(frameLength)} of {tableLength}</p> | ||
<button className="btn green" onClick={() => changePage(10)}><span>Next</span></button> | ||
</div> | ||
<div className="d-flex align-items-center"> | ||
<p className="m-4">Edit db limit: </p> | ||
<input type="number" onChange={e => setFrameLength(+e.target.value)} value={frameLength} /> | ||
<div className="spacer m-4"></div> | ||
<p className="m-4">Edit Rating filter: </p> | ||
<input type="number" onChange={e => setRatingState(+e.target.value)} value={ratingState} /> | ||
</div> | ||
<div className="d-flex align-items-center"> | ||
<button className="btn green m-4" onClick={getFirstRecord}><span>Get 1st Card</span></button> | ||
<div className="spacer m-4"></div> | ||
<button className="btn green m-4" onClick={manualFetch}><span>Manual Fetch</span></button> | ||
<button className="btn green m-4" onClick={unsubscribe}><span>Unsubscribe</span></button> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default UseReturnExample; |
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
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
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
Oops, something went wrong.