8000 Adding items to the page with `ServerLoad` · Issue #123 · pydantic/FastUI · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Adding items to the page with ServerLoad #123
Closed
@hasansezertasan

Description

@hasansezertasan

I cloned the repo and ran the demo and tried to modifie it so that I can ServerLoad items one by one, not just swap the ServerLoad

I modified this block:

c.Div(
components=[
c.Heading(text='Server Load', level=2),
c.Paragraph(text='Even simpler example of server load, replacing existing content.'),
c.Button(text='Load Content from Server', on_click=PageEvent(name='server-load')),
c.Div(
components=[
c.ServerLoad(
path='/components/dynamic-content',
load_trigger=PageEvent(name='server-load'),
components=[c.Text(text='before')],
),
],
class_name='py-2',
),
],
class_name='border-top mt-3 pt-1',
),

... like this:

        c.Div(
            components=[
                c.Heading(text="Server Load SSE", level=2),
                c.Markdown(text="`ServerLoad` can also be used to load content from an SSE stream."),
                c.Button(text="Load SSE content", on_click=PageEvent(name="server-load-sse")),
                c.Div(
                    components=[
                        c.ServerLoad(
                            path="/components/sse",
                            sse=True,
                            load_trigger=PageEvent(name="server-load-sse"),
                            components=[c.Text(text="before")],
                        ),
                    ],
                    class_name="my-2 p-2 border rounded",
                ),
            ],
            class_name="border-top mt-3 pt-1",
        ),

And I modified this block:

@router.get('/dynamic-content', response_model=FastUI, response_model_exclude_none=True)
async def modal_view() -> list[AnyComponent]:
await asyncio.sleep(0.5)
return [c.Paragraph(text='This is some dynamic content. Open devtools to see me being fetched from the server.')]

... like this:

@router.get("/dynamic-content", response_model=FastUI, response_model_exclude_none=True)
async def modal_view() -> list[AnyComponent]:
    await asyncio.sleep(0.5)
    return [
        c.Paragraph(
            text="This is some dynamic content. Open devtools to see me being fetched from the server."),
        c.ServerLoad(
            path="/components/dynamic-content",
            load_trigger=PageEvent(name="server-load"),
            components=[c.Text(text="before")],
        ),
    ]

It visually works but there is something wrong with the HTML Source Code

image

It's probably not a "bug" or something like that, it probably works as it should be and I probably using it wrong, just asking how to do it? Do what? This...

image

What I'm implementing? Let's say a simple TODO app, creating tasks but I don't want to get the entire demo_page and re-render everything, just append the new item...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0