Coder Social home page Coder Social logo

andrewjbateman / svelte-tailwind-ssr Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 1.57 MB

:clipboard: Svelte3 with Tailwind styles used to display API data in a SSR app

JavaScript 7.26% HTML 1.94% Svelte 57.19% TypeScript 27.47% CSS 6.14%
svelte3 tailwindcss css api-rest countries-api github-api rxjs7 rxjs-observables svelte tailwindcss-v3

svelte-tailwind-ssr's Introduction

โšก Svelte Tailwind SSR

  • Sveltejs kit used with Vite and RxJS & Tailwind CSS to display country & Github API data
  • Latest vite/Svelte3 folder layout using +page.server.ts to fetch server-side data to pass to +page.svelte client page.
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

๐Ÿ“„ Table of contents

๐Ÿ“š General info

  • Displays grid of Tailwind-styled cards, one for each country
  • Tailwind CSS card markup shown using separate card components
  • Search bar shows all countries that match the user search text
  • Country detail page uses the country alpha3 code in lower case as the unique id passed by route params.
  • About page gives details of the app with a Github link
  • Contact page gives info. on the author via the Github API
  • API endpoint: http://localhost:3000/api/countries/ shows all countries
  • API endpoint: http://localhost:3000/api/countries/id shows country with matching id
  • Unused Tailwind CSS is purged during build which makes for a much lighter bundle
  • REST API Endpoints

๐Ÿ“ท Screenshots

Frontend screenshot Frontend screenshot Frontend screenshot Frontend screenshot Frontend screenshot

๐Ÿ“ถ Technologies

  • Sveltejs/kit v1 Svelte & Vite-based framework
  • Svelte v3 React-based & created by Facebook (Meta), it is a fast, light and efficient front-end UI library/compiler that converts code to small bundles of highly-optimized ES6 vanilla JavaScript & declarative transitions. Does not use a virtual DOM. I have had to completely restructure the app due to Svelte/vite breaking version changes. A lot of companies use Svelte
  • Vite v4 Frontend Tooling dev server and build command for optimised build static assets.
  • RxJS v7 Reactive Extensions Library for JavaScript
  • Tailwind CSS v3 CSS framework
  • Tailwind Colour Palette
  • Online color converter, hex to Tailwind
  • REST Countries API v2 RESTful API with data on all world countries

๐Ÿ’พ Setup

  • npm i to install dependencies
  • npm run dev to run dev server on port localhost:3000
  • npm run build to build optimised version
  • npm run preview to run the newly built app

๐Ÿ”ง Testing

  • N/A

๐Ÿ’ป Code Examples

  • store/datastore.ts functions to fetch JSON data from Github & Restcountries APIs
// Fetch user data from Github REST API
const baseUrl = 'https://api.github.com/users/';
const userSearchUrl = `${baseUrl + 'AndrewJBateman'}`;
export const user = ajax({
	url: userSearchUrl
}).pipe(
	map((x) => x.response),
	startWith([])
);

// Fetch JSON data - 3 fields only - for all countries from Restcountries API
export const fetchCountries = async () => {
	const url = 'https://restcountries.com/v2/all?fields=name,flag,alpha3Code';
	const res = await fetch(url);
	const data = await res.json();
	const loadedData = data.map((data) => ({
		name: data.name,
		id: data.alpha3Code.toLowerCase(),
		image: data.flag
	}));
	countries.set(loadedData);
};

// Fetch JSON data on country with alpha3 code matching id from Restcountries API
export const fetchCountryById = async (id) => {
	if (countryDetails[id]) return countryDetails[id];

	try {
		const url = `https://restcountries.com/v2/alpha/${id}`;
		const res = await fetch(url);
		const data = await res.json();
		countryDetails[id] = data;
		return data;
	} catch (err) {
		console.error(err);
		return null;
	}
};

๐Ÿ†’ Features

  • Search input filtering
  • No API keys required
  • Tailwind results in a very compact bundle and helps with Lighthouse audit

๐Ÿ“‹ Status & To-Do List

  • Status: Working
  • To-Do: Change to API v3. Publish. Check Lighthouse score. Optimise for SSR. Add PWA? Add more API pages with nav-bar links. Add leaflet maps?

๐Ÿ‘ Inspiration

๐Ÿ“ License

  • This project is licensed under the terms of the MIT license.

โœ‰๏ธ Contact

svelte-tailwind-ssr's People

Contributors

andrewjbateman avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

matthiasgutsch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.