Duolith docs

social

The showcase feed app from the plan.

Run it

cargo run -p duolith-cli -- dev examples/social     # live, reloads on save
cargo run -p duolith-cli -- build examples/social   # static output in examples/social/dist

The folder on the web: examples/social.

Features it shows

FeatureWhereScreenshot
Rung 0 tables: files whose expressions are all constants build as a template and a table of constants, with none of their script (decision 0075)styling (5 of 6 pages), rust-module pages/about.duo, social pages/about.duo, navigation-kit library and settings/about, the kit and inputs-and-media index pagesduolith build examples/styling --report

Source

pages/about.duo
<screen title="About" class="p-4 gap-3 bg-canvas">
  <text class="text-title text-ink">About this example</text>
  <text class="text-body text-muted">
    One page file per screen. Utilities come from the theme, state updates only what reads it, and
    the same file compiles for web today and for iOS and Android next.
  </text>
  <text class="text-label text-primary" href="/">Back to the feed</text>
</screen>
pages/index.duo
---
import { state } from "@duolith/client";

type Post = { id: number; author: string; caption: string; likes: number };

let posts = state<Post[]>([
  { id: 1, author: "Ada", caption: "First light over the harbour.", likes: 12 },
  { id: 2, author: "Linus", caption: "New desk, same bugs.", likes: 4 },
  { id: 3, author: "Grace", caption: "Found the moth.", likes: 31 },
]);
let draft = state("");

function share() {
  const caption = draft.trim();
  if (caption === "") return;
  posts = [{ id: Date.now(), author: "You", caption, likes: 0 }, ...posts];
  draft = "";
}

function like(post: Post) {
  posts = posts.map((each) => (each.id === post.id ? { ...each, likes: each.likes + 1 } : each));
}
---

<screen title="Feed" class="p-4 gap-4 bg-canvas">
  <view class="row items-center justify-between">
    <text class="text-title text-ink">Feed</text>
    <text class="text-label text-primary" href="/about">About</text>
  </view>

  <view class="row gap-2 p-3 rounded-lg bg-surface border">
    <input
      class="grow px-3 py-2 rounded-md bg-raised text-body text-ink border"
      label="New post"
      placeholder="Share something"
      value={draft}
      on:input={(event) => (draft = event.value)}
    />
    <button
      class="px-4 py-2 rounded-md bg-primary text-on-primary text-label pressed:bg-ink"
      on:press={share}
    >
      Post
    </button>
  </view>

  <list each={posts} as="post" key={post.id} class="gap-3">
    <view class="card gap-2 p-4 rounded-lg bg-surface border">
      <text class="text-label text-muted">{post.author}</text>
      <text class="text-body text-ink">{post.caption}</text>
      <view class="row">
        <button class="row gap-2 text-label text-primary" label="Like" on:press={() => like(post)}>
          ♥ {post.likes}
        </button>
      </view>
    </view>
  </list>
</screen>

<style>
  .card {
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.06);
  }
</style>