Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow console.log #648

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
065894f
Add a topic field to account for non zero topics
Baleba Dec 5, 2023
b27881f
caniuse-lite from"1.0.30001352"to"1.0.30001566"
Baleba Dec 5, 2023
333dbc6
add text input for topic
Baleba Dec 5, 2023
9f768c6
add topic and bool for to extend topic feed use
Baleba Dec 5, 2023
1cc4c74
add website bool old and new topic use
Baleba Dec 5, 2023
52a0e88
add website and topic
Baleba Dec 5, 2023
645c923
Set feedtype control locally
Baleba Dec 8, 2023
5ec2e6a
Add Array based display of Postes, no data con yet
Baleba Dec 8, 2023
8864e5a
Limited impact on the code remove website bool
Baleba Dec 8, 2023
6fdc68b
Add screen to display posts from the feed when topic is not website.
Baleba Dec 13, 2023
8a39846
Add screen for data input in the case of feed with topic different fr…
Baleba Dec 13, 2023
ce15ece
Add button for managing Posting data.
Baleba Dec 13, 2023
5b0ca5f
Define post type and post array to be used in feed details.
Baleba Dec 13, 2023
30024c3
Add mode POST for upload origin.
Baleba Dec 13, 2023
0841679
change updateFeed to account for POST update.
Baleba Dec 13, 2023
6d9bc55
Create a dropdown list dynamically for identities to choose between.
Baleba Dec 15, 2023
92cd718
Changes related to choosing an Id for feed creation and update.
Baleba Dec 15, 2023
df49445
Update to display posts for a given feed.
Baleba Dec 15, 2023
836aacf
Adding a form to insert json objects as posts.
Baleba Dec 15, 2023
94643a8
Add a button in the upload options to include non website feeds updates.
Baleba Dec 15, 2023
7abdb46
Add some shared data in the Id contexte
Baleba Dec 15, 2023
fb1f82e
Add readFeed function to extract older posts from non website feeds.
Baleba Dec 15, 2023
0099e2a
allow console.log
Baleba Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/pages/account/feeds/AccountFeeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ExpandableListItem from '../../../components/ExpandableListItem'
import ExpandableListItemActions from '../../../components/ExpandableListItemActions'
import ExpandableListItemKey from '../../../components/ExpandableListItemKey'
import { SwarmButton } from '../../../components/SwarmButton'
import { SwarmTextInput } from '../../../components/SwarmTextInput'
import { Context as IdentityContext, Identity } from '../../../providers/Feeds'
import { ROUTES } from '../../../routes'
import { formatEnum } from '../../../utils'
Expand Down Expand Up @@ -98,7 +99,11 @@ export function AccountFeeds(): ReactElement {
<ExpandableListItem label="Identity type" value={formatEnum(x.type)} />
</ExpandableList>
</Box>
<ExpandableListItemKey label="Topic" value={'00'.repeat(32)} />
{x.topic === '' ? (
<ExpandableListItemKey label="Topic" value={'00'.repeat(32)} />
) : (
<SwarmTextInput name="Topic" label="Specific Feed Topic" formik />
)}
{x.feedHash && <ExpandableListItemKey label="Feed hash" value={x.feedHash} />}
<Box mt={0.75}>
<ExpandableListItemActions>
Expand Down
11 changes: 10 additions & 1 deletion src/pages/feeds/CreateNewFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ import { convertWalletToIdentity, generateWallet, persistIdentity } from '../../
interface FormValues {
identityName?: string
type?: IdentityType
website: boolean
topic: string
password?: string
}

const initialValues: FormValues = {
identityName: '',
type: 'PRIVATE_KEY',
password: '',
website: true,
topic: '00',
}

export default function CreateNewFeed(): ReactElement {
const { beeApi, beeDebugApi } = useContext(SettingsContext)
const { identities, setIdentities } = useContext(FeedsContext)
const [loading, setLoading] = useState(false)
const [website, setFeedType] = useState(true)
const { enqueueSnackbar } = useSnackbar()

const navigate = useNavigate()
Expand Down Expand Up @@ -108,7 +113,11 @@ export default function CreateNewFeed(): ReactElement {
</Box>
{values.type === 'V3' && <SwarmTextInput name="password" label="Password" password formik />}
<Box mt={2}>
<ExpandableListItemKey label="Topic" value={'00'.repeat(32)} />
{website ? (
<ExpandableListItemKey label="topic" value={'00'.repeat(32)} />
) : (
<SwarmTextInput name="topic" label="Specific Feed Topic" formik />
)}
</Box>
<Box mt={2} sx={{ bgcolor: '#fcf2e8' }} p={2}>
<Grid container justifyContent="space-between">
Expand Down
42 changes: 39 additions & 3 deletions src/pages/feeds/FeedSubpage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import X from 'remixicon-react/CloseLineIcon'
import { DocumentationText } from '../../components/DocumentationText'
import ExpandableListItemActions from '../../components/ExpandableListItemActions'
import ExpandableListItemKey from '../../components/ExpandableListItemKey'
import ExpandableList from '../../components/ExpandableList'
import ExpandableListItem from '../../components/ExpandableListItem'
import { HistoryHeader } from '../../components/HistoryHeader'
import { SwarmButton } from '../../components/SwarmButton'
import { Context as BeeContext } from '../../providers/Bee'
import { Context as IdentityContext } from '../../providers/Feeds'
import { Identity, Context as IdentityContext } from '../../providers/Feeds'
import { Context as SettingsContext } from '../../providers/Settings'
import { ROUTES } from '../../routes'
import { UploadArea } from '../files/UploadArea'
import { readFeed } from '../../utils/identity'

export function FeedSubpage(): ReactElement {
const { identities } = useContext(IdentityContext)
const { posts } = useContext(IdentityContext)
const { uuid } = useParams()
const { beeApi } = useContext(SettingsContext)
const { beeApi, beeDebugApi } = useContext(SettingsContext)
const { status } = useContext(BeeContext)

const navigate = useNavigate()
Expand All @@ -25,6 +29,19 @@ export function FeedSubpage(): ReactElement {

const identity = identities.find(x => x.uuid === uuid)

if (!beeApi || !beeDebugApi) {
return <></>
}

if (identity?.topic === '') {
} else {
try {
const readPostArray = readFeed(beeApi, beeDebugApi, identity as Identity)
} catch (error) {
return <></>
}
}

useEffect(() => {
if (!identity || !identity.feedHash) {
return
Expand All @@ -50,7 +67,11 @@ export function FeedSubpage(): ReactElement {
return (
<div>
<HistoryHeader>{`${identity.name} Website`}</HistoryHeader>
<UploadArea showHelp={false} uploadOrigin={{ origin: 'FEED', uuid }} />
{identity.topic === '' ? (
<UploadArea showHelp={false} uploadOrigin={{ origin: 'FEED', uuid }} />
) : (
<UploadArea showHelp={false} uploadOrigin={{ origin: 'POST', uuid }} />
)}
{available && identity.feedHash ? (
<>
<Box mb={4}>
Expand All @@ -72,6 +93,21 @@ export function FeedSubpage(): ReactElement {
</DocumentationText>
</Box>
)}
// Posts form
{posts.map((x, i) => (
<ExpandableList key={i} label={`${x.Title} Website`} defaultOpen>
<Box mb={0.5}>
<ExpandableList label={x.Title} level={1}>
<ExpandableListItem label="Post Type" value={x.Type} />
<ExpandableListItem label="Post Date" value={x.Date} />
<ExpandableListItem label="Post Amount" value={x.Amount} />
<ExpandableListItem label="Post Provider" value={x.Provider} />
<ExpandableListItem label="Post Place" value={x.Place} />
/* Add a clickable bzz link to a bill scan here */
</ExpandableList>
</Box>
</ExpandableList>
))}
<ExpandableListItemActions>
<SwarmButton iconType={X} onClick={onClose} cancel>
Close
Expand Down
95 changes: 85 additions & 10 deletions src/pages/files/Upload.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Box } from '@material-ui/core'
import { Form, Formik } from 'formik'
import { SwarmSelect } from '../../components/SwarmSelect'
import { SwarmTextInput } from '../../components/SwarmTextInput'
import { useSnackbar } from 'notistack'
import { ReactElement, useContext, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
Expand All @@ -8,7 +11,7 @@ import { ProgressIndicator } from '../../components/ProgressIndicator'
import TroubleshootConnectionCard from '../../components/TroubleshootConnectionCard'
import { META_FILE_NAME, PREVIEW_FILE_NAME } from '../../constants'
import { Context as BeeContext, CheckState } from '../../providers/Bee'
import { Identity, Context as IdentityContext } from '../../providers/Feeds'
import { Identity, Post, Context as IdentityContext } from '../../providers/Feeds'
import { Context as FileContext } from '../../providers/File'
import { Context as SettingsContext } from '../../providers/Settings'
import { EnrichedPostageBatch, Context as StampsContext } from '../../providers/Stamps'
Expand All @@ -23,6 +26,8 @@ import { PostageStampSelector } from '../stamps/PostageStampSelector'
import { AssetPreview } from './AssetPreview'
import { StampPreview } from './StampPreview'
import { UploadActionBar } from './UploadActionBar'
import ExpandableList from '../../components/ExpandableList'
import ExpandableListItemInput from '../../components/ExpandableListItemInput'

export function Upload(): ReactElement {
const [step, setStep] = useState(0)
Expand All @@ -41,6 +46,17 @@ export function Upload(): ReactElement {
const navigate = useNavigate()

const hasAnyStamps = stamps !== null && stamps.length > 0
const msg: Post = {
Title: 'PS5',
Type: 'Document',
Category: 'Loisir',
Date: '07/12/2023',
Amount: '750€',
Provider: 'Sony',
Place: 'La Defense',
reference: '',
}
const [PostData, setPostData] = useState(msg)

useEffect(() => {
refresh()
Expand Down Expand Up @@ -122,7 +138,6 @@ export function Upload(): ReactElement {
})
fls.push(packageFile(previewFile))
}

setUploading(true)

if (beeDebugApi) {
Expand All @@ -133,17 +148,24 @@ export function Upload(): ReactElement {
.uploadFiles(stamp.batchID, fls, { indexDocument, deferred: true })
.then(hash => {
putHistory(HISTORY_KEYS.UPLOAD_HISTORY, hash.reference, getAssetNameFromFiles(files))

// Load data in the Json/object
PostData.reference = hash.reference
if (uploadOrigin.origin === 'UPLOAD') {
navigate(ROUTES.HASH.replace(':hash', hash.reference), { replace: true })
} else {
updateFeed(beeApi, beeDebugApi, identity as Identity, hash.reference, stamp.batchID, password as string).then(
() => {
persistIdentity(identities, identity as Identity)
setIdentities([...identities])
navigate(ROUTES.ACCOUNT_FEEDS_VIEW.replace(':uuid', uploadOrigin.uuid as string), { replace: true })
},
)
updateFeed(
beeApi,
beeDebugApi,
identity as Identity,
hash.reference,
stamp.batchID,
PostData as Post,
password as string,
).then(() => {
persistIdentity(identities, identity as Identity)
setIdentities([...identities])
navigate(ROUTES.ACCOUNT_FEEDS_VIEW.replace(':uuid', uploadOrigin.uuid as string), { replace: true })
})
}
})
.catch(e => {
Expand All @@ -164,6 +186,10 @@ export function Upload(): ReactElement {
uploadFiles(password)
}

async function onSubmit(values: Post) {
setPostData(values)
}

return (
<>
{showPasswordPrompt && (
Expand Down Expand Up @@ -205,6 +231,55 @@ export function Upload(): ReactElement {
</>
)}
{step === 2 && stamp && <StampPreview stamp={stamp} />}
// Posts form
{uploadOrigin.origin === 'POST' && (
<Formik initialValues={msg} onSubmit={onSubmit}>
{({ submitForm, values }) => (
<Form>
<Box mb={0.25}>
<SwarmTextInput name="Title" label="" formik />
</Box>
<Box mb={0.25}>
<SwarmSelect
formik
name="Type"
options={[
{ label: 'Document', value: 'Document' },
{ label: 'Expenditure', value: 'Bill' },
]}
/>
</Box>
<Box mb={0.25}>
<SwarmSelect
formik
name="Category"
options={[
{ label: 'Groceries', value: 'Groceries' },
{ label: 'Petrol', value: 'CarPetrol' },
{ label: 'Non Petrol Car', value: 'CarFix' },
{ label: 'Travel', value: 'Travel' },
{ label: 'Medical', value: 'Medical' },
{ label: 'Investment', value: 'Investment' },
]}
/>
</Box>
<Box mb={0.25}>
<SwarmTextInput name="Date" label="" formik />
</Box>
<Box mb={0.25}>
<SwarmTextInput name="Amount" label="" formik />
</Box>
<Box mb={0.25}>
<SwarmTextInput name="Provider" label="" formik />
</Box>
<Box mb={0.25}>
<SwarmTextInput name="Place" label="" formik />
</Box>
</Form>
)}
</Formik>
)}
// Post Form
<UploadActionBar
step={step}
onCancel={reset}
Expand Down
Loading