Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

10.3 KB
Raw Blame
import { Meta, StoryFn, StoryObj } from '@storybook/nextjs';
import { Provider } from 'jotai';
import { http, HttpResponse } from 'msw';
import { FollowerCollection } from './FollowerCollection';

const mockFollowersData = {
  total: 100,
  results: [
    {
      link: 'https://fedi-test.example.social/users/feditestc21c4124',
      name: '',
      username: '[email protected]',
      image: '',
      timestamp: '2022-04-28T09:00:00Z',
      disabledAt: null,
    },
    {
      link: 'https://an-extremely-long-fediverse-server-hostname.example.technology/users/somebodywithareallylongusername',
      name: 'Somebody With A Really Long Display Name',
      username:
        'somebodywithareallylongusername@an-extremely-long-fediverse-server-hostname.example.technology',
      image: '',
      timestamp: '2022-04-28T08:00:00Z',
      disabledAt: null,
    },
    {
      link: 'https://sun.minuscule.space/users/mardijker',
      name: 'mardijker',
      username: '[email protected]',
      image:
        'https://sun.minuscule.space/media/336af7ae5a2bcb508308eddb30b661ee2b2e15004a50795ee3ba0653ab190a93.jpg',
      timestamp: '2022-04-27T12:12:50Z',
      disabledAt: null,
    },
    {
      link: 'https://mastodon.online/users/Kallegro',
      name: '',
      username: '[email protected]',
      image: '',
      timestamp: '2022-04-26T15:24:09Z',
      disabledAt: null,
    },
    {
      link: 'https://mastodon.online/users/kerfuffle',
      name: 'Kerfuffle',
      username: '[email protected]',
      image:
        'https://files.mastodon.online/accounts/avatars/000/133/698/original/6aa73caa898b2d36.gif',
      timestamp: '2022-04-25T21:32:41Z',
      disabledAt: null,
    },
    {
      link: 'https://mastodon.uno/users/informapirata',
      name: 'informapirata :privacypride:',
      username: '[email protected]',
      image:
        'https://cdn.masto.host/mastodonuno/accounts/avatars/000/060/227/original/da4c44c716a339b8.png',
      timestamp: '2022-04-25T11:38:23Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/Raeanus',
      name: 'Raeanus',
      username: '[email protected]',
      image:
        'https://gamethattune.club/media/a6e6ccea-34f8-4c2e-b9dc-ad8cca7fafd3/DD14E3BF-1358-4961-A900-42F3495F6BE2.jpeg',
      timestamp: '2022-04-23T00:46:56Z',
      disabledAt: null,
    },
    {
      link: 'https://mastodon.ml/users/latte',
      name: 'Даниил',
      username: '[email protected]',
      image:
        'https://mastodon.ml/system/accounts/avatars/107/837/409/059/601/386/original/c45ec2676489e363.png',
      timestamp: '2022-04-19T13:06:09Z',
      disabledAt: null,
    },
    {
      link: 'https://wienermobile.rentals/users/jprjr',
      name: 'Johnny',
      username: '[email protected]',
      image: '',
      timestamp: '2022-04-14T14:48:11Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/johnny',
      name: 'John Regan',
      username: '[email protected]',
      image:
        'https://gamethattune.club/media/3c10cd89-866b-4604-ae40-39387fe17061/profile_large.jpg',
      timestamp: '2022-04-14T14:42:48Z',
      disabledAt: null,
    },
    {
      link: 'https://mastodon.social/users/MightyOwlbear',
      name: 'Haunted Owlbear',
      username: '[email protected]',
      image:
        'https://files.mastodon.social/accounts/avatars/107/246/961/007/605/352/original/a86fc3db97a6de04.jpg',
      timestamp: '2022-04-14T13:33:03Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/fourthwall',
      name: ':fourthwall: █████ :fourthwall: (( MagmaSys ))',
      username: '[email protected]',
      image: '',
      timestamp: '2022-04-05T12:23:32Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/TheBaffler',
      name: 'TheBaffler',
      username: '[email protected]',
      image: '',
      timestamp: '2022-04-04T19:50:08Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/Gttjessie',
      name: 'Gttjessie',
      username: '[email protected]',
      image: '',
      timestamp: '2022-03-30T20:18:47Z',
      disabledAt: null,
    },
    {
      link: 'https://cybre.space/users/fractal',
      name: 'Le fractal',
      username: '[email protected]',
      image:
        'https://cybre.ams3.digitaloceanspaces.com/accounts/avatars/000/405/126/original/f1f2832a7bf1a967.png',
      timestamp: '2022-03-30T19:46:17Z',
      disabledAt: null,
    },
    {
      link: 'https://fosstodon.org/users/jumboshrimp',
      name: 'alex 👑🦐',
      username: '[email protected]',
      image: 'https://cdn.fosstodon.org/accounts/avatars/000/320/316/original/de43cda8653ade7f.jpg',
      timestamp: '2022-03-30T18:09:54Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/nvrslep303',
      name: 'Tay',
      username: '[email protected]',
      image: 'https://gamethattune.club/media/5cf9bc27-8821-445a-86ce-8aa3704acf2d/pfp.jpg',
      timestamp: '2022-03-30T15:27:49Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/anKerrigan',
      name: 'anKerrigan',
      username: '[email protected]',
      image: '',
      timestamp: '2022-03-30T14:47:04Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/jgangsta187',
      name: 'jgangsta187',
      username: '[email protected]',
      image: '',
      timestamp: '2022-03-30T14:42:52Z',
      disabledAt: null,
    },
    {
      link: 'https://gamethattune.club/users/aekre',
      name: 'aekre',
      username: '[email protected]',
      image: '',
      timestamp: '2022-03-30T14:41:32Z',
      disabledAt: null,
    },
    {
      link: 'https://fosstodon.org/users/owncast',
      name: 'Owncast',
      username: '[email protected]',
      image:
        'https://cdn.fosstodon.org/accounts/avatars/107/017/218/425/829/465/original/f98ba4cd61f483ab.png',
      timestamp: '2022-03-29T21:38:02Z',
      disabledAt: null,
    },
    {
      link: 'https://cybre.space/users/wklew',
      name: 'wally',
      username: '[email protected]',
      image:
        'https://cybre.ams3.digitaloceanspaces.com/accounts/avatars/000/308/727/original/7453e74f3e09b27b.jpg',
      timestamp: '2022-03-29T18:24:29Z',
      disabledAt: null,
    },
    {
      link: 'https://mastodon.social/users/nvrslep303',
      name: 'Tay',
      username: '[email protected]',
      image:
        'https://files.mastodon.social/accounts/avatars/108/041/196/166/285/851/original/fc444dd6096381af.jpg',
      timestamp: '2022-03-29T18:19:31Z',
      disabledAt: null,
    },
    {
      link: 'https://mastodon.social/users/morky',
      name: '',
      username: '[email protected]',
      image: '',
      timestamp: '2022-03-29T18:17:59Z',
      disabledAt: null,
    },
    {
      link: 'https://mastodon.social/users/jgangsta187',
      name: 'John H.',
      username: '[email protected]',
      image: '',
      timestamp: '2022-03-29T18:15:48Z',
      disabledAt: null,
    },
    {
      link: 'https://fosstodon.org/users/meisam',
      name: 'Meisam 🇪🇺:archlinux:',
      username: '[email protected]',
      image: 'https://cdn.fosstodon.org/accounts/avatars/000/264/096/original/54b4e6db97206bda.jpg',
      timestamp: '2022-03-29T18:12:21Z',
      disabledAt: null,
    },
  ],
};

const noFollowersData = {
  total: 0,
  results: [],
};

const singleFollowerData = {
  total: 1,
  results: mockFollowersData.results.slice(0, 1),
};

const meta = {
  title: 'owncast/Components/Followers/Followers collection',
  component: FollowerCollection,
  parameters: {
    chromatic: { diffThreshold: 0.86 },
  },
} satisfies Meta<typeof FollowerCollection>;

export default meta;
type Story = StoryObj<typeof meta>;

const Template: StoryFn<typeof FollowerCollection> = (args: object) => (
  <Provider>
    <FollowerCollection onFollowButtonClick={() => {}} name="Example stream name" {...args} />
  </Provider>
);

export const NoFollowers = {
  render: Template,

  parameters: {
    msw: {
      handlers: [
        http.get('/api/followers*', () => {
          return HttpResponse.json(noFollowersData);
        }),
      ],
    },
  },
};

const singleFollowerStory = {
  render: Template,
  args: {
    name: 'Example stream name',
    onFollowButtonClick: () => {},
  },

  parameters: {
    msw: {
      handlers: [
        http.get('/api/followers*', () => {
          return HttpResponse.json(singleFollowerData);
        }),
      ],
    },
  },

  play: async ({ canvasElement }) => {
    const deadline = Date.now() + 5000;
    let follower: HTMLElement | null = null;

    while (!follower && Date.now() < deadline) {
      follower = canvasElement.querySelector<HTMLElement>('.followers-follower');
      if (!follower) {
        const { promise, resolve } = Promise.withResolvers<void>();
        window.setTimeout(resolve, 100);
        // eslint-disable-next-line no-await-in-loop
        await promise;
      }
    }

    const collection = canvasElement.querySelector('#followers-collection');
    if (!follower || !collection) {
      throw new Error('Single follower story did not render');
    }

    const collectionWidth = collection.getBoundingClientRect().width;
    const followerWidth = follower.getBoundingClientRect().width;
    if (collectionWidth >= 600 && followerWidth > collectionWidth / 2) {
      throw new Error('Single follower expanded beyond one grid column');
    }
  },
} satisfies Story;

export const SingleFollowerOfflineFullWidth = {
  ...singleFollowerStory,
  parameters: {
    ...singleFollowerStory.parameters,
    chromatic: { viewports: [1568] },
  },
} satisfies Story;

export const SingleFollowerOnlineWithChatWidth = {
  ...singleFollowerStory,
  decorators: [
    Story => (
      <div style={{ width: 'calc(100% - 320px)' }}>
        <Story />
      </div>
    ),
  ],
  parameters: {
    ...singleFollowerStory.parameters,
    chromatic: { viewports: [1568] },
  },
} satisfies Story;

export const Example = {
  render: Template,

  parameters: {
    msw: {
      handlers: [
        http.get('/api/followers*', () => {
          return HttpResponse.json(mockFollowersData);
        }),
      ],
    },
  },
};